Uninstall MSI with VBScript

Uninstall MSI with VBScript

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.
3.75
Average: 3.8 (52 votes)
AttachmentSize
UninstallMSI.zip1015 bytes

Obtaining the GUID

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

Uninstall fails when run with System rights

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.

Uninstalling Applications

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

Less code

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!

MSI API code

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

UNinstalling MSI Without using VBscript

Anovatek 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

I think you are replying to the wrong thread

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...

ha haa..

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..!!

Syndicate content