SCRIPT: Delete old Windows Update backup files

The following script can be used as a scheduled task on workstations. It deletes old Windows Update backup files which are morely overhead than useful.

Option Explicit
Dim o, oShell, nConfirm
Set o = WScript.Application
o.Interactive = True
Set oShell = CreateObject("WScript.Shell")

Dim oFSO, sWinDir, oFolder, oDictionary, oSubFolder, sFolderName, sFolderPath, sUpdateName, sDeleted
Set oFSO = CreateObject("Scripting.FileSystemObject")
sWinDir = oFSO.GetSpecialFolder(0)
sDeleted = vbNullString
Set oFolder = oFSO.GetFolder(sWinDir)
Set oDictionary = CreateObject("Scripting.Dictionary")
For Each oSubFolder In oFolder.SubFolders
'Zoek de verschillen Hint: het zit um in één regel :-)
sFolderName = LCase(oSubFolder.Name)
sFolderPath = LCase(oSubFolder.Path)
'change days here
If (DateDiff("D", oSubFolder.DateCreated, Date()) > 90) And Left(sFolderName, 12) = "$ntuninstall" And Mid(sFolderName, 13, 2) = "kb" Or Mid(sFolderName, 13, 2) = "q" Then
sUpdateName = Mid(sFolderName, 13, Len(sFolderName) - 13)
oDictionary.Add sUpdateName, sFolderPath
End If
Next

For Each sUpdateName in oDictionary.Keys
sDeleted = sDeleted & vbCrLF & sUpdateName
sFolderPath = oDictionary.Item(sUpdateName)
On Error Resume Next
oShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & sUpdateName & "\"
oShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Management\ARPCache\" & sUpdateName & "\"
On Error Goto 0
oShell.Run "%ComSpec% /C RD /S /Q " & Chr(34) & sFolderPath & Chr(34), 0, True
Next
'If Len(sDeleted) > 0 Then
' MsgBox "The uninstall data for the following updates are now removed:" & vbCrLf & UCase(sDeleted), vbOKOnly + vbInformation, "Files Removed"
' sDeleted = vbNullString
'Else
' MsgBox "No Windows Update Folders found for removal", vbOKOnly + vbInformation, "Nothing To Do"
'End If
o.Quit 0

Advertisements

Posted on 27/01/2010, in Windows. Bookmark the permalink. Leave a comment.

Comments are closed.

%d bloggers like this: