I updated a Win7 box with SP1 and upgrade the browser to IE11. I would like to delete any files that are not required for operations (i.e. install files, etc.) so as to avoid archiving them unnecessarily with Clonezilla. Is there a good script, list or procedure that supports this objective? Thank you


Windows 7 Cleanup Script and Processes

Below is a batch script I've used in the past to cleanup Windows 7 and Windows Vista machines before imaging so give it a shot if you want.

See sysprep and consider using it too and run it and once the machine powers down, you will want to take an image with CloneZilla then before it boots back up to Windows.

Batch Script

I'd be sure to look through the script and comment anything out that you don't want to include in the process and test this on a test machine beforehand as well just to be safe nothing needed is cleaned or removed for your need.

This is a batch script so just save this to a text document with a .cmd or .bat file extension, and be sure to right-click to run elevated as administrator too.

I do know that some of these processes are redundant as well but I've just not gotten a chance to clean up these duplicate processes but it won't hurt to run a delete or cleanup process on the same folder, etc. twice anyway.

@ECHO on

TASKKILL /F /IM explorer.exe

ECHO *****""Stopping Windows Services""****
NET STOP /Y "Themes"
NET STOP /Y "Windows Update"
NET STOP /Y "Print Spooler"
NET STOP /Y "Remote Registry"
NET STOP /Y "Background Intelligent Transfer Service"
NET STOP /Y "Office Source Engine"
NET STOP /Y "Offline Files"
NET STOP /Y "Secondary Logon"
NET STOP /Y "Java Quick Starter"
NET STOP /Y "smart card"
NET STOP /Y "Tablet PC Input Service"
NET STOP /Y "Telephony"
NET STOP /Y "Windows Media Player Network Sharing Service"
NET STOP /Y "Windows Mobile 2003-based device connectivity"
NET STOP /Y "Windows Mobile-based device connectivity"
NET STOP /Y "Cisco Systems, Inc. VPN Service"
NET STOP /Y "Adobe LM Service"
NET STOP /Y "Adobe Flash Player Update Service"
NET STOP /Y "Bluetooth Support Service"

SC CONFIG "Adobe Flash Player Update Service" START= manual
SC CONFIG "Adobe LM Service" START= manual
SC CONFIG "Fax" START= manual
SC CONFIG "Offline Files" START= manual
SC CONFIG "Java Quick Starter" START= manual
SC CONFIG "Tablet PC Input Service" START= manual
SC CONFIG "Windows Media Player Network Sharing Service" START= manual
SC CONFIG "Windows Mobile 2003-based device connectivity" START= manual
SC CONFIG "Windows Mobile-based device connectivity"" START= manual

::Setting Source Directories as Variables
SET SRC1=C:\Users
SET SRC2=AppData\Local\Temp
SET SRC3=AppData\Local\Microsoft\Windows\Temporary Internet Files
SET SRC4=AppData\Local\Microsoft\Windows\History
SET SRC5=AppData\Microsoft\Windows\Cookies
SET SRC6=AppData\Local\Microsoft\Windows\WER
SET SRC7=AppData\Local\Microsoft\Windows\Explorer
SET SRC8=AppData\Local

ECHO ****Deleting User\AppData\Local\Temp Sub-Directories****
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\") DO RMDIR /S /Q "%%Y"

ECHO ***Deleting User\AppData\Local\MS\Windows\Temporary Internet Files***
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"

ECHO ***Deleting User\AppDate\Local\MS\Windiws\History Sub-Directories***
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC4%\") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"

ECHO **Deleting User\AppData\Local\Microsoft\Windows\Cookies Sub-Directories**
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC5%\*.*") DO DEL /F /S /Q "%%Y"

ECHO **Deleting User\AppData\Local\Microsoft\Windows\WER\ReportArchive & Report Queue**
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC6%\*.*") DO DEL /F /S /Q "%%Y"

ECHO **Deleting User\AppData\Local\Microsoft\Windows\Explorer**
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC7%\*.*") DO DEL /F /S /Q "%%Y"

ECHO ****""Deleting Non-User Temp files and directories""****
RMDIR /S /Q C:\WINDOWS\SoftwareDistribution
DEL /F /S /Q %TEMP%\*.*
DEL /F /S /Q %systemroot%\temp\*.*
DEL /F /S /Q C:\ProgramData\TEMP\*.*
DEL /F /S /Q C:\Windows\Temp\*.*
DEL /F /S /Q %windir%\Temp\*.*
FOR /D %%X IN ("%windir%\temp\*") DO RMDIR /S /Q "%%X"

ECHO **Recreate all %userprofile%\Appdata\Local\Temp\Low directory**
FOR /D %%X IN (%SRC1%\*) DO FOR /D %%Y IN (%%X\%SRC8%) DO MD %%Y\Temp\Low

ECHO **Set security level back up on all %userprofile%\Appdata\Local\Temp\Low directory**          
FOR /D %%X IN (%SRC1%\*) DO FOR /D %%Y IN (%%X\%SRC8%) DO ICACLS %%Y\Temp\Low /setintegritylevel (OI)(CI)low

ECHO ** Remove all print jobs that are pendning**
DEL /Q /F "%systemroot%\system32\spool\printers\*.shd"
DEL /Q /F "%systemroot%\system32\spool\printers\*.spl"

::Empty all recycle bins
RD /S /Q C:\recycler

ECHO *** Turn off Windows hibernation power save setting ***

ECHO *** Resize VSS (shadow storage) ***

ECHO *** Set disk cleanup parameters to clean and then clean after being set ***

ECHO *** Flush DNS ***

ECHO *** Reset TCP/IP ***

ECHO *** Reset Winsock ***



Dism Commands

Note: If you get an error 1260, then that likely means you have System Restore disabled in Group Policy or something along those lines. So just enabled System Restore and then rerun these commands from an administrator elevated command prompt. Additionally, you may need to run CD /D "C:\Windows\System32" before running each of the below commands.

The following command will uninstall all previous versions of components without the scheduled task’s 30-day grace period:

DISM.exe /online /Cleanup-Image /StartComponentCleanup

The following command will remove files needed for uninstallation of service packs. You won’t be able to uninstall any currently installed service packs after running this command:

DISM.exe /online /Cleanup-Image /SPSuperseded

The following command will remove all old versions of every component. You won’t be able to uninstall any currently installed service packs or updates after this completes:

DISM.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase\


Further Resources

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.