Q. How can I use a script to uninstall a service pack?
November 23, 2004
A. One of my clients recently had to remove Windows XP Service Pack 2 (SP2) from a system on which it had been accidentally deployed. You can use the following script, Removesp.vbs (which a friend gave me and I modified a bit), to silently remove the service pack (in this case, XP SP2) and reboot the computer. (You can download the script at Download. After you extract the script, save it as removesp.vbs.)
strComputer = "."Set WshShell = WScript.CreateObject("WScript.Shell")Set objWMIService =GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer& "rootcimv2")Set colOperatingSystems = objWMIService.ExecQuery("Select * fromWin32_OperatingSystem")For Each objOperatingSystem in colOperatingSystems If objOperatingSystem.ServicePackMajorVersion = "2" Then WshShell.Run"%windir%$NtServicePackUninstall$spuninstspuninst.exe -u -f", 1,True WshShell.Run "%windir%system32shutdown.exe -r -f -t 5 -c " &chr(34) & "Service Pack 2 has been uninstalled from your computer. Thecomputer will now be restarted." & chr(34) End IfNext
You can call Removesp.vbs from a standard logon script by using a line of code similar to this:
wscript \domainetlogonscript.vbs
You might want to customize the script so that it also checks for the current OS version. As is, Removesp.vbs uninstalls SP2 on any OS for which an SP2 exists. You can use the objOperatingSystem.Version attribute to return a value that identifies the OS. Some common values include
5.0.2195: Windows 2000 Server
5.1.2600: XP
5.2.3790: Windows 2003
For example, to check for the existence of SP2 on only XP systems, you'd change the conditional statement
If objOperatingSystem.ServicePackMajorVersion = "2" Then
to this:
If objOperatingSystem.ServicePackMajorVersion = "2" andobjOperatingSystem.Version = "5.1.2600" Then
About the Author
You May Also Like