![clean disk c clean disk c](http://www.wikihow.com/images/f/f6/Permanently-Remove-Files-from-Your-Hard-Drive-Step-7.jpg)
![clean disk c clean disk c](https://www.sysprobs.com/wp-content/uploads/2010/02/largestfile.png)
If you save the above script to “cleanmgr.ps1” you can then deploy it to numerous computers using the BatchPatch deployment feature. # Create registry values $volumeCaches = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches" foreach ( $key in $volumeCaches ) In particular please note that it actually creates a StateFlags0123 DWORD with value of 2 in *all* of the subkeys under this registry key: This way you can then use a BatchPatch deployment to deploy your script, the script will create the desired StateFlagsXXXX registry values on the target computers, execute cleanmgr.exe with the appropriate SAGERUN switch to make use of the StateFlagsXXXX registry values that were set by the script, and then optionally delete the registry values it previously created. Then evaluate which registry values it created, and then write a script that will create the same registry values. OK, so what you can do to automate everything is run the cleanmgr tool with /SAGESET on a single computer. SAGESET:124 would create registry values titled StateFlags0124. The StateFlags0123 values were created when I ran cleanmgr.exe with the /SAGESET:123 switch. I’ve pasted below just a few of the keys/values, but in particular please note the StateFlags0123 REG_DWORD values that exists in the subkeys. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches The way these switches work is you manually run the following command on a particular computer at the cmd prompt: In the above link you can see that the cleanmgr.exe tool has two important switches: /SAGESET and /SAGERUN However, you can’t simply use /SAGERUN without some setup. However, cleanmgr.exe does have a way of executing silently/quietly without any user interaction: The /SAGERUN switch. In the case of cleanmgr.exe, if you run it without any consideration for the fact that it is being run hidden and remotely, its default mode will pop a dialog that will hang indefinitely since it cannot be acknowledged. No dialog boxes will be seen, and so instead what happens is the deployment appears to hang indefinitely while the package waits for the hidden dialog boxes to be acknowledged. The problem is that when a deployment runs remotely, it is hidden. If you execute a remote deployment without specifying the proper silent/quiet installation switch, the installer package attempts to run interactively, which means that it pops up dialog boxes that it expects the user to acknowledge. This is essentially the same problem that we discuss in numerous places on this website when it comes to silent application deployment. The user noted that when running cleanmgr.exe in BatchPatch on a target computer, the cleanmgr.exe would stay running indefinitely.
Clean disk c how to#
We recently received a question about how to successfully run the Windows Disk Cleanup Tool remotely using BatchPatch.