Asset Management Suite

 View Only

Uninstall Windows Installer Applications Using VBScript 

Nov 24, 2008 11:58 AM

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.

Statistics
0 Favorited
0 Views
2 Files
0 Shares
2 Downloads
Attachment(s)
jpg file
6359.jpg   4 KB   1 version
Uploaded - Feb 25, 2020
zip file
Uninstall Script.zip   741 B   1 version
Uploaded - Feb 25, 2020

Tags and Keywords

Comments

Feb 19, 2010 12:36 PM

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

Nov 26, 2008 10:31 AM

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

Nov 26, 2008 09:48 AM

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

Nov 25, 2008 01:14 PM

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?
:)

Related Entries and Links

No Related Resource entered.