Forum Discussion
Need Syntax Help w Batch File Script - it deletes junk files after Win Cleanup is Done
So I put this script on over 100 computers, ran them for months. Worked fabulous! Often cleared an extra 1 GB of junk files right after I was done with regular MS cleanup. If I ran it again by accident a second time, still maintained integrity, just echoing 'files not found.'
One day I shared this with a friend overseas. He ran it as I watched.. and it began to delete his entire system32 folder! And a few weeks later, it happened again, as I was remotely running it on PC I was cleaning up for a client. (file script was already hosted on the target pc)
Since batch files drop to C:/windows/system32 by default when it runs in PowerShell, I know that for some reason my script syntax on the 'delete commands' are wrong.
Why it works 99% of the time is still a mystery, though
-- begin my shared script in this forum ---
pause
echo. Cleanup Root Directory
echo. Press any key when ready..
@echo off
RMdir "c:\$WinREAgent\Scratch"
RMdir "c:\$WinREAgent"
pause
echo. Cleanup USERS ADMIN TEMP
echo. Press any key when ready..
@echo off
CD "c:\Users\Admin\AppData\Local\Temp\"
Del * /s /q
RMdir * /s /q "c:\Users\Admin\AppData\Local\Temp\"
pause
echo. Cleanup SOFTWARE DIST DOWNLOAD
echo. Press any key when ready..
CD "c:\Windows\SoftwareDistribution\Download\"
Del * /s /q
RMdir * /s /q "c:\Windows\SoftwareDistribution\Download\"
pause
exit
-- end my shared script on this forum ---