Video Screencast Help
Symantec Appoints Michael A. Brown CEO. Learn more.

Uninstall MSI with VBScript

Created: 04 Apr 2008 | 16 comments
dallasr's picture
0 0 Votes
Login to vote

I'm sure you've come across times when you need to deploy an application, but before you can install it, you need to make sure another application is uninstalled. Whether that other application is a previous version of the new application or just something that isn't compatible with the new application. Or maybe you just need to remove an application from a system without installing anything new. I put together this script to handle these situations and have used it many times.

Note that this script will only handle MSI-based applications, however I will be providing some more scripts to assist with uninstalling non-msi based applications as well. All you need to get this working for you is the Product Code of the installed MSI that you want to uninstall.

The easiest way to find the Product Code is to look at the property table of the MSI you want to remove. You can use ORCA or Wise Package Studio for viewing the property table of an MSI. When you view the property table, you will see the ProductCode property and it's value listed there.

Once you have the Product Code you need then enter it into the vbscript up at the top where it says:

Const Productcode = "{00000000-0000-0000-0000-000000000000}"

Make sure that you enter the {}'s and -'s as well just like the sample product code in the script.

Then save it and it's ready to go. You can then run this script in a DS or Software Delivery job to uninstall the intended application.

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 16 CommentsJump to latest comment

gbromage's picture

You can also obtain the GUID or product code by searching through the Add/Remove Programs list. Here's a sample VBscript that will uninstall Adobe Reader:

'Remove Adobe Reader
'vbscript
On Error Resume Next

'**********************************************************************
const AppName = "Adobe Reader"
'**********************************************************************

const HKEY_LOCAL_MACHINE = &H80000002

Set WshShell = WScript.CreateObject("WScript.Shell")

'First, find the GUID 
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_ 
    strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
    InstalledAppName = ""
    InstalledAppName = WshShell.RegRead("HKLM\" & strKeyPath & "\" & subkey & "\DisplayName")

    If InStr(InstalledAppName, AppName) > 0 then
	RawGUID = ""
	GUID = ""
        RawGUID = WshShell.RegRead("HKLM\" & strKeyPath & "\" & subkey & "\UninstallString")
        GUID = Mid(RawGUID, instr(RawGUID, "{"), 38)
	If GUID<>"" then
	    ' Found matching GUID, removing...
	    	    WshShell.Run "msiexec /x " & GUID & " /q"
	    Exit For
	End If
    End If
Next

+1
Login to vote
MoAltiris's picture

Whether I'm using a VBS or Batch or just the command line "msiexec.exe /uninstall /myapp.msi /quiet" it will fail when run with System rights! Any of the above methods work fine when tested locally on the machine by any administrator account.

This is a SWD and if I specify a user it will fail since we have Security Groups as administrators on the local machine. Can I specify a local user account like "administrator"? This job would run on many computers with different names. I tried %computername% in the "Domain" field, which did not work. I don't want to hard code a username or password in a script.

Any ideas would be helpful!!
Thanks.

0
Login to vote
mcsereed's picture

You can also find this information in the registry in the uninstall folder in HKLM.

0
Login to vote
Kinetic's picture
itemGUID = "{00000000-0000-0000-0000-000000000000}"

Return = WshShell.Run("msiexec.exe /x" & itemGUID & " /qb!", 1, true)

If return <> 0 or return <> 3010
WshShell.Popup "Uninstall failed. Error Code" & Return
Wscript.Quit()
End If

If you are creating an SWD package you can just put the follwing into the program command:

msiexec.exe /x{00000000-0000-0000-0000-000000000000} /qb!
0
Login to vote
looeee's picture
Const ProductCode = "{00000000-0000-0000-0000-000000000000}"

Const msiInstallStateAbsent = 2
On Error Resume Next

Set oInstaller = CreateObject("WindowsInstaller.Installer")
oInstaller.UILevel = 99
oInstaller.ConfigureProduct ProductCode, 0, msiInstallStateAbsent

If Err <>0 Then
	WScript.Echo Err.Source & " " & Hex(Err) & vbNewLine & Err.Description
End If
0
Login to vote
TilakGovind's picture

Even the above requirement is done by using batch file

which contains a commandLine to UNinstall the .MSI

Soon i will write a article how to do it..

Cheers Tillu

Cheers Tillu

0
Login to vote
looeee's picture

your subject is "UNinstalling MSI Without using VBscript"

but this is the "uninstall msi with vbscript" thread. I think one or both of us are confused.

is this what you meant? http://juice.altiris.com/article/3944/uninstalling...

0
Login to vote
R-Vijay's picture

Must be he mentioned that, there is another way to un-install the package without using the vbscript., and he is intending to write an article on it. :-) he eheee....

so its an info for this author to watch out for..!!

Microsoft MVP [Setup-Deploy]
Weblog: www.msigeek.com

0
Login to vote
ghass's picture

This is excellent but what if I am removing an application which have different version and the display name is made of something like Adobe Reader 9.0 and some other version Adobe reader 8.0 what I need to put in the const AppName = "" . I will add Adove reader * or ?

Thank you

0
Login to vote
bakkerro's picture

If both versions have "Adobe Reader" in their name and you want both of them uninstalled, then just use "Adobe Reader" as value. Any application with "Adobe Reader" in its name will be uninstalled!

0
Login to vote
bakkerro's picture

There is a shorter way to get the same thing done using Win32_Product (In my example the application ApplicationName is Uninstalled:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSoftware = objWMIService.ExecQuery _
    ("Select * from Win32_Product Where Name = 'ApplicationName'")

For Each objSoftware in colSoftware
    objSoftware.Uninstall()
Next

You must have the complete name for the application. The following example is like the one showed by dallasr:

const AppName="Adobe Reader"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSoftware = objWMIService.ExecQuery _
    ("Select * from Win32_Product")

For Each objSoftware in colSoftware
    If Instr(ObjSoftware.Name,AppName) Then
      objSoftware.Uninstall()
    End If
Next

0
Login to vote
ahen0342's picture

I did not get an error but the application was not removed. Should I use the Application name listed under program files or under control panel\add and remove programs they are different. Tried both but neither one worked.

0
Login to vote
rx7turbo1's picture

bakkerro, you can actually use wildcards here... I have been using the following sub routine with great success. Depending on the machine, it takes about 5-20 seconds for WMI to scan the registry verse knowing the product guid ahead of time. But this code is super simple and uninversal.

Sub Uninstall
On Error Resume Next
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colSoftware = objWMIService.ExecQuery("Select * from Win32_Product Where Name LIKE 'Adobe%'")
For Each objSoftware In colSoftware
    objSoftware.Uninstall()
Next
End Sub

0
Login to vote
rx7turbo1's picture

The difference is using a LIKE and %%'s. SQL code works the same with WMI.

0
Login to vote
bakkerro's picture

Indeed it is. I simply reused the code used to display all installed apps, but with the sql selection it is more efficient, thanks!

0
Login to vote
RDAdams's picture

Is there a way to remove the progress of the uninstall from a clients computer?

I want to eliminate user visuals for this process?

0
Login to vote