VBScript: Uninstall Updates on winXP,Win2003, Win7 and Win 2008 R2 automatically!

Download “UninstallUpdates-1.0.2.zip” UninstallUpdates-1.0.2.zip – Downloaded 1182 times – 2 KB

The Challenge

Microsoft has changed the way updates are being installed and uninstalled many times. This means that a common method can’t be used.

Windows XP and Windows 2003

  • Updates can be uninstalled from a hidden “uninstall” folder, located in the windows folder.  Windows 2008 R2 and Windows 7
  • A command line utility (wusa.exe) can uninstall the updates.

The solution

The solution contains one VBScript, this script is able to detect the local OS, and use one of the 2 methods above for uninstall.

XP/2003:

  • The script does a check for the uninstall folder, and run the spuninst.exe
  • The script writes event log event (Source: WSH) in the local event log describing if it was found it not.
  • More logging can be enabled by the /log argument, and a text field will be created on the local machine

Win7/2k8R2:

  • Script runs built-in the wusa.exe command.
  • The script does no check if the update is installed before trying to uninstall the update, since wusa.exe have no method for doing this.
  • Wusa.exe writes status messages to event log.
  • Wusa.exe supported /log argument, but it does not write text files, therefore a .evt file will be saved (if a path for another type of file is specified, it will automatically be changed to .evt to make the file usable.)

The Flowchart later in this document describes this in a more detailed way.

The script will end with success, no matter if the update exists on the machine or not. If it fails, something else is wrong (for example: bad command line in the ConfigMgr Program).

 

Known Issues

  • Windows 2008 (non R2) is Not Supported. It does not have the “old” uninstall folders in Windows folder, and “wusa.exe” utility does not support uninstallation.
  • Some updates cannot be uninstalled, even if we try to do it manually.
  • Other updates for Microsoft applications might not be possible to uninstall in this generic way
  • 3rd party application updates or service packs cannot be uninstalled.
  • Specific updates might use a non-standard installation method, which makes it impossible to uninstall (at least on XP/2003)

Using the script

Run the script with cscript.exe.

This is an example of the basic command line for running the script:

 

cscript.exe UninstallUpdates.vbs 976902

 

Syntax is

 

cscript.exe <scriptname> <kb number> <arguments>

 

this means you are able to use arguments for changing the behavior of the uninstall

 

 

Supported Arguments:
Argument Description
/passive This disables the /quiet argument, and makes a progressbar visible for the user.(requires the user to be able to interact with the program in ConfigMgr)
/norestart Disable automatic restart when using /quiet
/forcerestart Force a restart after uninstall, no matter if it is needed or not.
/warnrestart Warn user before restarting(requires the user to be able to interact with the program in ConfigMgr)
/log:”C:\temp\uninstall.log” Create a log file on the local machine.XP/2003: Text file

7/2K8R2: .evt eventlog file.

Notice there is no space between /log: and the path.

Allways surround the path with “ “ to make sure that it is parsed correctly.

To use argument in a command line

cscript.exe UninstallUpdates.vbs 976902 /norestart /log:”C:\KB976902-Uninstall.log”

Exit Codes

The script has a couple of custom exit codes.

You might experience other exit codes, if you have error in script, command line or similar.

Exit Code Description
10001 No arguments supplied, at least one argument (KB Number) is required!

 

a Thank you goes out to DFDS A/S

Script

 


 

By | 2012-04-24T10:46:52+00:00 April 24th, 2012|Scripting & Development|5 Comments

About the Author:

Jakob Gottlieb Svendsen

Twitter: @JakobGSvendsen

Jakob Gottlieb Svendsen is a Microsoft Cloud and Data Center Management MVP (http://mvp.microsoft.com/en-us/default.aspx), Working as Global Lead Developer, Senior Consultant and Trainer at CTGlobal, where he is one of the driving forces in keeping CTGlobal a System Center Gold Partner and member of the System Center Alliance.

Since he started at Coretech in 2007, he has focused on Scripting and Development, primarily developing tools, extensions and scripts for the System Center Suite. His main area is Automation (including OMS/Azure Automation, Service Management Automation, PowerShell and Orchestrator). Another area is Windows Azure Pack / Azure Stack, where he does implementation, development, workshops and presentations. He is a world-wide renowned voice in the Automation field.

He is passionately devoted to the community, to which he contributes by being a moderator at TechNet and sharing his knowledge at http://blog.ctglobalservices.com/jgs

  • Co-founder: PowerShell User Group Denmark
  • Speaker at MMS 2016, Minneapolis (www.mmsmoa.com)
  • SCU Europe 2014, 2015, 2016 (www.systemcenteruniverse.ch)
  • Microsoft TechEd North America 2014, Houston
  • NIC 2012,2013,2014,2015, Oslo (www.nic.com)
  • Microsoft CampusDays 2011, 2013, Copenhagen
  • Microsoft TechDays 2015, Sweden (www.techdays.se)
  • Microsoft Partner Event: New in SC2012 SP1
  • User group meetings (PSUG.DK , SCUG.DK/BE/NO, AZMUG + more)
  • Microsoft Certified Trainer.
  • Microsoft Scripting Guys Forum Moderator

Main working areas:

  • Automation (Azure Automation, SMA, SCO)
  • Windows Azure Pack / Azure Stack
  • System CenterVisual Studio Team Services / Team Foundation Server
  • Development:C#.Net, VB.NET, VBScript, PowerShell, Service Manager, OpsMgr, ConfigMgr
  • Orchestrator
  • Windows Azure Pack / Azure Stack

Training:

  • Azure Automation
  • Service Management Automation
  • System Center Orchestrator
  • PowerShell, VBScript, C#.Net, VB.Net
  • Windows Azure Pack / Azure Stack Development Workshops

5 Comments

  1. Application Management July 28, 2012 at 17:14 - Reply

    Thanks for the script….

  2. Fabio August 27, 2012 at 14:31 - Reply

    Great script!!!! It was very useful ( http://social.technet.microsoft.com/Forums/pt-BR/scriptadminpt/thread/4c8ac7b5-6053-48fa-829b-bf293a6a8911 )

    suggestion:

    Change line:
    strCurrentKB = Mid(strFolderName, InStr(strFolderName, “kb”) + 2, 6)

    to

    strCurrentKB = Mid(strFolderName, InStr(strFolderName, “kb”) + 2, len(strKBNumber))

  3. chandra May 20, 2017 at 1:58 - Reply

    can any one help install windows updates using VB script for windows 2003 and 2008 servers

Leave A Comment