Q. How can I use a script to uninstall a service pack?

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
& "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery("Select * from
Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems

    If objOperatingSystem.ServicePackMajorVersion = "2" Then

        WshShell.Run
"%windir%\$NtServicePackUninstall$\spuninst\spuninst.exe -u -f", 1,
True
        WshShell.Run "%windir%\system32\shutdown.exe -r -f -t 5 -c " &
chr(34) & "Service Pack 2 has been uninstalled from your computer. The
computer will now be restarted." & chr(34)

    End If

Next

You can call Removesp.vbs from a standard logon script by using a line of code similar to this:

wscript \\domain\netlogon\script.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" and
objOperatingSystem.Version = "5.1.2600" Then
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish