Obtaining Product Code to Uninstall Applic.
I am writing a script to uninstall an application if it exists on my local PC AND if there is a newer version of the software. I know how to use the msiexec.exe tool to uninstall via the command line, simply by typing:
msiexec /x <product code> /qn
The above statement performs an uninstall without user prompts (from what I understand). Without using a "hard-coded" product code in my script (if I knew what it was), how do I obtain it in order to perform the uninstall?
Please advise. Thanks.
Re: Obtaining Product Code to Uninstall Applic.
I noticed quite a few views to my question, but no feedback/replies.
Well, strange as it may seem, I actually found the solution to this issue. In order to find the product code, I need to create a Windows Installer object, go through the products property which contains the product code for all products installed according to the Windows Installer. For each product code, I extract the name of the application, and compare it to the target application name...if there is a match, I capture the target product code and use it in my command line to uninstall the target application. To illustrate, my code block looks like this:
Set installer = CreateObject("WindowsInstaller.Installer")
For Each prod In installer.products
ProdName = installer.productinfo(prod, "InstalledProductName")
If (InStr(1, ProdName, "<TargetApp>") > 0) And (InStr(1, ProdName, "<NonTargetAppSubStr1>") <= 0) And (InStr(1, ProdName, "<NonTargetAppSubStr2") <= 0) Then
TestLog.Comment "Found product key"
ProdCode = prod //assign found product key
If ProdCode <> "" Then //if the product key was found, perform the uninstall on that application
TestLog.Comment "Auto-Uninstall in Progress"
ShellStr = "MsiExec.exe /x" & ProdCode & " /qn"
FileNum = Shell(ShellStr, vbMinimizedFocus)
TestLog.Comment "Could not find product key"
Solution source: http://community.flexerasoftware.com...d.php?t=87139. Hope this helps all of you who may be struggling to extract the product code for the purposes of uninstalling the application, or for any other purpose.