In the previous post we introduced the Windows tool cleanmgr and its parameters /sageset and /sagerun that you can use to define and run automated hard disk cleanups.

Today we’ll be looking into how you can customize the actual cleanup tasks performed by cleanmgr.exe.

This tool stores all configuration in the Windows Registry at this location: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches

Below, you find keys for every cleanup task that cleanmgr can do. In our previous tip we defined a custom cleanup task like so (remember to run it with full Admin privileges):

 
PS> cleanmgr.exe /sageset:5388   
 

The call opens a dialog window where you can check the cleaning tasks that should be tied to the submitted ID 5388.

Once you close the dialog, these settings can be found in the Windows Registry:

# the ID you picked when saving the options:
$id = 5388

# the name of the reg value that stores your choices:
$flag = "StateFlags$id" 

# the location where user choices are stored:
$path = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\*"

# get all subkeys where your user choice was enabled:
Get-Item -Path $path |
  Where-Object { $_.Property -contains $flag }  # contains your registry value (StateFlags5388)
  Where-Object { $_.GetValue($flag) -gt 0 }     # your registry value contains a number greater than 0

And in fact, the result is exactly listing the cleaner modules you previously checked in the selection dialog:

 
Name                           Property
----                           --------
Active Setup Temp Folders      (default)      : {C0E13E61-0CC6-11d1-BBB6-0060978B2AE6}
                               Autorun        : 1
                               Description    : These files should no longer be needed. They were originally 
                                                created by a setup program that is no longer running.
                               FileList       : *.tmp
                               Flags          : {124, 0, 0, 0}
                               Folder         : C:\Windows\msdownld.tmp|?:\msdownld.tmp
                               LastAccess     : {2, 0, 0, 0}
                               Priority       : 50   
                               StateFlags0001 : 2
                               StateFlags0003 : 2
                               StateFlags0033 : 0
                               StateFlags6254 : 0
                               StateFlags5388 : 2
BranchCache                    (default)      : {DE661907-527D-4d6a-B6A6-EBC7F88D9B95}
                               StateFlags0001 : 0
                               StateFlags0003 : 0
                               StateFlags0033 : 0
                               StateFlags6254 : 0
                               StateFlags5388 : 2
D3D Shader Cache               (default)      : {D8D133CD-3F26-402F-86DA-90B710751C2C}
                               Autorun        : 1
                               ReserveIDHint  : 2
                               StateFlags0001 : 0
                               StateFlags0003 : 0
                               StateFlags0033 : 0
                               StateFlags6254 : 0
                               StateFlags5388 : 2
Delivery Optimization Files    (default)      : {4057C1AD-A51F-40BB-B960-22888CEB9812}
                               Autorun        : 0
                               Description    : @C:\WINDOWS\system32\domgmt.dll,-104
                               Display        : @C:\WINDOWS\system32\domgmt.dll,-103
                               Flags          : 128  
                               ReserveIDHint  : 2
                               StateFlags0001 : 0
                               StateFlags0003 : 0
                               StateFlags0033 : 0
                               StateFlags6254 : 0
                               StateFlags5388 : 2
Diagnostic Data Viewer         (default)        : {C0E13E61-0CC6-11d1-BBB6-0060978B2AE6}
database files                 Autorun          : 0
                               CleanupString    : rundll32.exe utcutil.dll,DiskCleanupEnd
                               Description      : @C:\WINDOWS\system32\utcutil.dll,-302
                               Display          : @C:\WINDOWS\system32\utcutil.dll,-301
                               FileList         : *.*
                               Flags            : 573
                               Folder           : C:\ProgramData\Microsoft\Diagnosis\EventTranscript\
                               IconPath         : C:\WINDOWS\system32\utcutil.dll,0
                               PreCleanupString : rundll32.exe utcutil.dll,DiskCleanupStart
                               Priority         : 100
                               StateFlags0001   : 0  
                               StateFlags0003   : 0  
                               StateFlags0033   : 0  
                               StateFlags6254   : 0  
                               StateFlags5388   : 2  
Downloaded Program Files       (default)          : {8369AB20-56C9-11D0-94E8-00AA0059CE02}
                               AdvancedButtonText : @C:\Windows\System32\occache.dll,-1072
                               Autorun            : 1
                               Description        : @C:\Windows\System32\occache.dll,-1071
                               Display            : @C:\Windows\System32\occache.dll,-1070
                               Priority           : {100, 0, 0, 0}
                               StateFlags0001     : 2
                               StateFlags0003     : 2
                               StateFlags0033     : 0
                               StateFlags6254     : 2
                               StateFlags5388     : 2
Internet Cache Files           (default)          : {9B0EFD60-F7B0-11D0-BAEF-00C04FC308C9}
                               AdvancedButtonText : &View Files
                               Autorun            : 1
                               Description        : The Temporary Internet Files folder contains Web pages stored 
                                                    on your hard disk for quick viewing.
                                                    Your personalized settings for Web pages will be left intact. 
                               Display            : Temporary Internet Files
                               Priority           : 100
                               StateFlags0001     : 2
                               StateFlags0003     : 2
                               StateFlags0033     : 0
                               StateFlags6254     : 2
                               StateFlags5388     : 2
Language Pack                  (default)      : {191D5A6B-43B9-477A-BB22-656BF91228AB}
                               Autorun        : 1
                               StateFlags0001 : 0
                               StateFlags0003 : 0
                               StateFlags0033 : 0
                               StateFlags6254 : 0
                               StateFlags5388 : 2
Old ChkDsk Files               (default)      : {C0E13E61-0CC6-11d1-BBB6-0060978B2AE6}
                               Autorun        : 1
                               FileList       : *.CHK
                               Flags          : 288
                               Folder         : ?:\FOUND.000|?:\FOUND.001|?:\FOUND.002|?:\FOUND.003|?:\FOUND.004|
                                                ?:\FOUND.005|?:\FOUND.006|?:\FOUND.007|?:\FOUND.008|?:\FOUND.009
                               IconPath       : C:\WINDOWS\System32\DATACLEN.DLL,3
                               Priority       : 50   
                               PropertyBag    : {60F6E464-4DEF-11d2-B2D9-00C04F8EEC8C}
                               StateFlags0001 : 2
                               StateFlags0003 : 2
                               StateFlags0033 : 0
                               StateFlags6254 : 2
                               StateFlags5388 : 2
Recycle Bin                    (default)      : {5ef4af3a-f726-11d0-b8a2-00c04fc309a4}
                               PluginType     : 2 
                               StateFlags0001 : 2
                               StateFlags0003 : 0
                               StateFlags0033 : 0
                               StateFlags6254 : 0
                               StateFlags5388 : 2
 

Each cleaner module has a unique GUID in “(default)”. As you see, the GUID “{C0E13E61-0CC6-11d1-BBB6-0060978B2AE6}” is used by a number of cleaner modules. This is a generic file remover module that you can easily use in your own file cleaner modules. Simply add a new subkey to the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches, use the GUID mentioned above inside of it, and configure which files this cleaner should find and delete. You may want to look at existing cleaners such as “Old ChkDsk Files” in regedit.exe to find out the names of the registry values that define the files to delete.




Twitter This Tip! ReTweet this Tip!

Anonymous