VBscript to uninstall a Microsoft security patch

This is a small script I wrote many years ago to uninstall security patches.  I customise it when I need it.

In this example, I’ve customised it for MS09-032, but the principles apply to most patches.

Note that I don’t check for admin rights, I’m assuming that I’ll be using a desktop software deployment tool to run it on the user’s desktop.

' VBscript to roll back a security patch, in this case MS09-032.
‘ Dale Robinson – 2006 –> 2009

Option Explicit
On Error Resume Next

Dim bUninstallFileExists, OSSystemRoot, objWSHShell, objEnv, sMS09032Installed, sPatchCmd,sUninstallExe

Set objWSHShell = WScript.CreateObject("WScript.Shell")
Set objEnv = objWSHShell.Environment("Process")

' MS09-032 sets this registry key if it's installed.

sMS09032Installed = objWSHShell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Updates\Windows 2000\SP5\KB973346\Description")

' the path to the Uninstall exe for the security patch.
sUninstallExe = "C:\WINNT\$NtUninstallKB973346$\spuninst\spuninst.exe"

sPatchCmd = sUninstallExe + " /quiet"

' if sMS09032Installed has something in it, it means the patch is currently installed.
If sMS09032Installed <> "" Then
' check that the uninstall .exe exists on the PC we're running on it.
Call fn_CheckIfFileExists (sUninstallExe, bUninstallFileExists)
If bUninstallFileExists Then
objWSHShell.Run sPatchCmd
End If
End If


Function fn_CheckIfFileExists(fnFilePathName, boolResult)
Dim objFSO, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(fnFilePathName)
If objFSO.FileExists(fnFilePathName) Then
boolResult = True
boolResult = False
End If
Set objFSO = Nothing
End Function

Bookmark and Share

Comments are closed.