Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.

Uninstall Windows Installer Applications Using VBScript

Created: 24 Nov 2008 • Updated: 11 Mar 2009 | 4 comments
Sidd's picture
+9 9 Votes
Login to vote

The following script will uninstall Windows Installer based Applications in silent mode. Script will take ProductCode of the application as an input, you just need to specify the Product Code of the application.

 
Option Explicit 'all variables must be defined

Dim oReg, oShell, oFSO 
Dim UninstallString, ProductCode
Dim strComputer, colItems, objWMIService, objItem
Dim strKeyPath, subkey, arrSubKeys
strComputer = "." 

'********************************
'Enter Product Code Of The Application Here That You Want To Uninstall within the Bracket 
ProductCode = "{AC76BA86-1033-0000-7760-000000000004}" 

'********************************

' Get scripting objects needed throughout script.
Set oShell = CreateObject("WScript.Shell")

'**************************
UninstallString = "MsiExec.exe /X" & ProductCode & " /qn" & " /norestart"

Const HKEY_LOCAL_MACHINE = &H80000002

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
 
For Each subkey In arrSubKeys 
 
 IF subkey = ProductCode Then 
 oShell.Run UninstallString, 1, True
 End If

Next

Set oShell = Nothing
Set oReg = Nothing
'************* End Code ************

Note: There Should be an entry of product Code under the following registry, if not found the script will exit (without any error). "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

For your convenience, I've attached a script.

I hope this will help.

Thanks,
Sid

License: AJSL
By clicking the download link below, you agree to the terms and conditions in the Altiris Juice Software License
Support: User-contributed tools on the Juice are not supported by Altiris Technical Support. If you have questions about a tool, please communicate directly with the author by visiting their profile page and clicking the 'contact' tab.

Comments 4 CommentsJump to latest comment

haim96's picture

i published a script with similar outcome but my script build automatically the uninstall string.
(from registry)

in most of the applications keys you can find the key:
"UninstallString" that contain the uninstall string as the value.

so why not use it?

:)

0
Login to vote
Eshwar's picture

Thats a good point haim96

Infact this script is restricted to PRODUCT CODE.
I mean to say, the script is only looking for an entry of PRODUCT CODE under

"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

What about applications that doesn't have an entry of PRODUCT CODE under the above mentioned hive?

For example Internet Explorer 7 has "UninstallString" entry under
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ie7"

We can use the value of "UninstallString" to uninstall IE7

"UninstallString" = "C:\WINDOWS\ie7\spuninst\spuninst.exe"

And one more point to add:
If there is no PRODUCT CODE then the script is simply exiting without any return value. The script should return a value in case of successful/unsuccessful executions. I would recommend a retun value of "1" in case there is no PRODUCT CODE.
Ex:
wscript.quit(0) for success
wscript.quit(1) for failure

Cheers,

Eshwar

+3
Login to vote
Sidd's picture

If any one is looking for capturing exit codes of uninstallation of application using the script then use oShell.Run as a function.

Here is the modified script with exit codes.

Option Explicit 'all variables must be defined

Dim oReg, oShell, oFSO
Dim UninstallString, ProductCode, i
Dim strComputer, colItems, objWMIService, objItem
Dim strKeyPath, subkey, arrSubKeys
strComputer = "."

'********************************
'Enter Product Code Of The Application Here That You Want To Uninstall within the Bracket
ProductCode = "{AC76BA86-1033-0000-7760-000000000004}"

'********************************

' Get scripting objects needed throughout script.
Set oShell = CreateObject("WScript.Shell")

'**************************
UninstallString = "MsiExec.exe /X" & ProductCode & " /qn" & " /norestart"

Const HKEY_LOCAL_MACHINE = &H80000002

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys

IF subkey = ProductCode Then
i=0
i= oShell.Run(UninstallString, 1, True)
WScript.Quit(i)
End If

Next

Set oShell = Nothing
Set oReg = Nothing
'************* End Code ************

Thanks,

Sid

+11
Login to vote
Rmun's picture

Sidd,

I used your script with success but it continues to display the Uninstall splash screen and reboots the system. If there alternative switches for XP that will prevent these events from occurring?

Thanks
RMun

0
Login to vote