Client – HDD-Cleanup

Hello together,

as some of you know i have worked in a 3rd level support desk and we created some scripts to make our daily work easier. Here i want to show you one of these. It is pretty easy written but very effective.

Execute EXECCLEANUP.bat as Administrator with the files SET1337.reg and clearcache.vbs in the same directory.

Download all files from here.

Initial file:

@echo off
::
:: Author: David das Neves
:: Datum: 12.01.2015
echo   ***************************************************************************
echo ********                                                               ********
echo ********                     Clearing SCCM-Cache                       ********
echo ********                                                               ********
echo  *****************************************************************************
cd %~dp0
cscript clearcache.vbs

echo   ***************************************************************************
echo ********                                                               ********
echo ********            Deleting Temporary Internet Files                  ********
echo ********                                                               ********
echo  *****************************************************************************
c:
cd c:\users\
for /f "delims=" %%a in ('dir /ad /b /s "Temporary Internet Files"') do echo "%%a" & rd /s /q "%%a" 

echo  *****************************************************************************
echo ********                                                               ********
echo ********                 Deleting unused OST-Files                     ********
echo ********                                                               ********
echo  *****************************************************************************
cd\
cd c:\users
for /F "delims=" %%a in ('dir /b /aD') do echo "%%a\AppData\Local\Microsoft\Outlook\*.ost" & del /Q "%%a\AppData\Local\Microsoft\Outlook\*.ost"

echo   ***************************************************************************
echo ********                        HDD-Cleanup                            ********
echo *******************************************************************************
echo  *****************************************************************************
echo ****                          Setting Regs                                 ****
echo  *****************************************************************************
regedit /s Set1337.reg

echo   ************************************************************************
echo  *****                  HDD-Cleanup in progress                    ********
echo  *****                         Please wait ....                    ********
echo  *****                The procedure will take some time.           ********
echo  **************************************************************************
Cleanmgr /sagerun:1337
::Cleanmgr /sagerun:65535 

echo   ***************************************************************************
echo ********                     HDD-Cleanup finished!                     ********
echo *******************************************************************************
pause

With the reg-file we modify the cleanmgr properties in the registry to clean up every possible option which is normally hidden. We do this with a new created ID 1337. For more  technical background of this property read on and give a look in here.

StateFlags REG_DWORD By running the disk cleanup manager’s executable file—Cleanmgr.exe—from a command line, you can declare cleanup profiles. These profiles are composed of a subset of the available handlers and are given a unique numeric label. This allows you to automate the running of different sets of handlers at different times.

The command line “cleanmgr.exe /sageset:nnnn“, where nnnn is a unique numeric label, displays a UI allowing you to choose the handlers to be included in that profile. As well as defining the profile, the sageset parameter also writes a value named StateFlagsnnnn, where nnnn is the label you used in the parameter, to all of the subkeys underVolumeCaches. There are two possible data values for those entries.

  • 0: Do not run this handler when this profile is run.
  • 2: Include this handler when this profile is run.

For example, suppose that the command line “cleanmgr.exe /sageset:1234” is run. In the UI that is presented, the user choosesDownloaded Program Files, but does not choose Temporary Internet Files. The following values are then written to the registry.

HKEY_LOCAL_MACHINE
   Software
      Microsoft
         Windows
            CurrentVersion
               Explorer
                  VolumeCaches
                     Downloaded Program Files
                        StateFlags1234 = 0x00000002
                     Internet Cache Files
                        StateFlags1234 = 0x00000000

The command line “cleanmgr.exe /sagerun:nnnn“, where the value ofnnnn matches the label declared with the sageset parameter, runs all of the handlers selected in that profile.

A generic StateFlags value is written to the registry when Disk Cleanup is run normally. This value simply stores the state (checked or unchecked) of the handler the last time it was presented as an option to the user. There are two possible data values for those entries.

  • 0: The handler was not selected.
  • 1: The handler was selected.

I hope you enjoy it!

Greetings,
Dave.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s