Last active
February 18, 2016 07:11
-
-
Save dstaulcu/74f1769aa8774c9a4420 to your computer and use it in GitHub Desktop.
Automate creation of cleanup task profile and execute corresponding tasks. This is a fork of example code in https://gallery.technet.microsoft.com/scriptcenter/Cleanup-Windows-581c1933 having cleanup tasks of interest to a particular case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
On Error Resume Next | |
' Fork from https://gallery.technet.microsoft.com/scriptcenter/Cleanup-Windows-581c1933 | |
' allowing for definition of desired cleanup tasks | |
SetRegKeys | |
DoCleanup | |
Sub DoCleanup() | |
Dim WshShell | |
Set WshShell=CreateObject("WScript.Shell") | |
WshShell.Run "C:\WINDOWS\SYSTEM32\cleanmgr /sagerun:1",0,False | |
End Sub | |
Sub SetRegKeys | |
Dim strKeyPath | |
Dim strComputer | |
Dim objReg | |
Dim arrSubKeys | |
Dim SubKey | |
Dim strValueName | |
Dim iNewDwordValue | |
Const HKLM=&H80000002 | |
strKeyPath="SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches" | |
strComputer="." | |
strValueName="StateFlags0001" | |
Set objReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv") | |
objReg.Enumkey HKLM ,strKeyPath,arrSubKeys | |
For Each SubKey In arrSubKeys | |
Select Case subKey | |
Case "Previous Installations" | |
iNewDwordValue=2 | |
Case "Service Pack Cleanup" | |
iNewDwordValue=2 | |
Case "Temporary Setup Files" | |
iNewDwordValue=2 | |
Case "Update Cleanup" | |
iNewDwordValue=2 | |
Case "Upgrade Discarded Files" | |
iNewDwordValue=2 | |
Case Else | |
iNewDwordValue=0 | |
End Select | |
objReg.SetDWORDValue HKLM,strKeyPath & "\" & SubKey,strValueName,iNewDwordValue | |
Next | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment