Jump to content

Batch script to clean things on Windows


Recommended Posts

Hi guys. I need a little help here.

I was searching for some batch script to do some tasks on windows 7, 8 and 10 machines and I found some interesting topic. I grab the script and I made some changes. Now I need to make the script to work and I need your help to make the changes I wrote on the script itself.

If possible, please, jaclass or somebody else, help me..

The sketch for the script is:

IMPORTANT: Whe the user run this script it must get elevate privilegies automaticaly (as run as administrator do).

ECHO """BATCH SCRIPT TO CLEAN THINGS!!!

"This script will clean things from your computer. Press Y to continue or N to cancel.."

If the user type Y then show the message above and continue with the script:

"Message: Doing the things. This can take a little.."

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
SET /A Counter=0
FOR %%A IN (
"c:\windows\prefetch\*.*"
"c:\windows\temp\*.*"
"c:\windows\tmp\*.*"
"c:\tmp\*.*"
"c:\temp\*.*"
"c:\WINDOWS\ShellIconCache\*.*"
"c:\Users\%username%\AppData\Roaming\Microsoft\Windows\Recent Items\*.*"
"%userprofile%\Cookies\*.*"
"%UserProfilePath%\Local Settings\Temp\"
"%UserProfilePath%\Local Settings\Temporary Internet\*.*"
"%UserProfilePath%\Application Data\Sun\Java\Deployment\cache\*.*"
"%UserProfilePath%\AppData\LocalLow\Sun\Java\Deployment\cache\*.*"
"%UserProfilePath%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*"
"%UserProfilePath%\AppData\Local\Temp\*.*"
"%UserProfilePath%\AppData\LocalLow\Temp\*.*"
"%homepath%\Appdata\Local\Temp\*.*"
"c:\temp\*.*"
"%homepath%\Local Settings\Temporary Internet Files\*.*"
 "%homepath%\Local Settings\Temp\*.*

) DO (
CALL :do_count %%A
CALL :do_del %%A
)

GOTO :EOF

:do_count
FOR /F %%B IN ('dir /b %1') DO (
SET /A Counter+=1
ECHO !Counter!
)
GOTO :EOF

:do_del
ECHO del %1
GOTO :EOF

When everything is done show a message to the user asking him to reboot the system:

"Message: All task where done. Now, please, type R to reboot the computer or L to do it later.."

Thats it. If mistakes where made, please correct and show me whats wrong so I can learn too.

DEdit.: OH!!! It would be nice if the script could show messages when the task get done, one by one, like:

Clean of "c:\windows\temp\*.*": DONE!

Clean of ""c:\windows\tmp\*.*": DONE!

and so on... :3

Edited by yro
Link to comment
Share on other sites



And of course you don't cite the references to what you found.

No problem, though, the batch is in this topic here:

and (but this is just a guess) you got the %userprofilepath% variable from here:
http://superuser.com/questions/832681/batch-delete-temporary-windows-files-system-browsers-cache-etc-for-all-user

but it is seemingly undefined in your "sketch".

The very simplified batch was posted to answer a specific question and to show the OP a possible way to do what he asked which may (or may not) be the right thing to do and to show a (hopefully clear) "skeleton" for the batch

Namely the procedure of counting (why?) the number of files deleted will slow down the procedure (if there are many directories and files) and if the scope is to actually clean *everything* it doesn't take into account (as an example) hidden files and folders (or read only files).

If you prefer, one thing is a "half-@§§ed" quick, simple example batch, but to go from that to a "safe" (or reasonably safe), "foolproof" (at least to the extent something can be foolproof) and "working" (or reasonably working) on different systems batch there is a huuuge gap, and this gap should be filled by your learning the language (as opposed to have someone else writing the batch for you).

Really :), if you have issues in understanding where to insert in that batch the command to "show message when the task get done, one by one" you will need to study some more the basics of the scripting language and exercise yourself with something less (potentially) dangerous.

Mind you it is not about "not helping you", it is actually about attempting to help you.

Try figuring out the sequence of commands in that batch where the command to show the message should be put, try finding some example of user interaction routines (prompting the user for the Y and later for the R or L),  etc.

In other words try writing the batch yourself, if there are mistakes or if you have a specific issue/doubt I am pretty sure everyone will try and help you, but right now you are essentially asking other people to write the batch along some "guidelines" you devised, this way you won't likely learn anything and it is improbable that someone will write the whole thing for you).

jaclaz
 

Link to comment
Share on other sites

5 hours ago, jaclaz said:


And of course you don't cite the references to what you found.

No problem, though, the batch is in this topic here:

and (but this is just a guess) you got the %userprofilepath% variable from here:
http://superuser.com/questions/832681/batch-delete-temporary-windows-files-system-browsers-cache-etc-for-all-user

but it is seemingly undefined in your "sketch".

The very simplified batch was posted to answer a specific question and to show the OP a possible way to do what he asked which may (or may not) be the right thing to do and to show a (hopefully clear) "skeleton" for the batch

Namely the procedure of counting (why?) the number of files deleted will slow down the procedure (if there are many directories and files) and if the scope is to actually clean *everything* it doesn't take into account (as an example) hidden files and folders (or read only files).

If you prefer, one thing is a "half-@§§ed" quick, simple example batch, but to go from that to a "safe" (or reasonably safe), "foolproof" (at least to the extent something can be foolproof) and "working" (or reasonably working) on different systems batch there is a huuuge gap, and this gap should be filled by your learning the language (as opposed to have someone else writing the batch for you).

Really :), if you have issues in understanding where to insert in that batch the command to "show message when the task get done, one by one" you will need to study some more the basics of the scripting language and exercise yourself with something less (potentially) dangerous.

Mind you it is not about "not helping you", it is actually about attempting to help you.

Try figuring out the sequence of commands in that batch where the command to show the message should be put, try finding some example of user interaction routines (prompting the user for the Y and later for the R or L),  etc.

In other words try writing the batch yourself, if there are mistakes or if you have a specific issue/doubt I am pretty sure everyone will try and help you, but right now you are essentially asking other people to write the batch along some "guidelines" you devised, this way you won't likely learn anything and it is improbable that someone will write the whole thing for you).

jaclaz
 

I know I know. The references I dont quote because they are from here (and I had closed the tab with these references when posting this topic).

Youre right. Im going to try it out for myself and eventualy Ill post some questions in here in hope somedoby helps.. I know You and other on this forum are great guys/girls and You always helped me. This time Ill do the crazy script and Ill be posting my results to go foward..

Please, dont lock this topic. This may take a while but Ill be posting in here... God help me with this studies because He knows Im in a trick situation, doing school, working and taking care of family.. But lets go for it..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...