I have an application installed on my machine. I also have its source code but somehow the ProductCode and UpgradeCode of this application were changed.
Now I want t
Hadn't found any way of finding out the UpgradeCode from an installed application, before seeing Yan Sklyarenko's workaround (currently) above. But if you/anyone else would find a way of finding out (at least) both UpgradeCode and ProductCode from a MSI, read on.
From http://www.dwarfsoft.com/blog/2010/06/22/msi-package-code-fun/, modified to allow (when launched with wscript.exe
) one popup box of info per MSI (Trunicated at 1023 chars, due to wscript.echo
limitation); able to input MSI(s) from the GUI as well as the CLI; some basic human input validation; removed debug code (' Set oDatabase) and 1 bug fix (DB.OpenView).
'Created by: Chris Bennett
'Created Date: 22/06/2010
'Description:
' Opens up MSI file(s) Passed as Arguments & returns ProductName, ProductCode,
' The HKCR key created from ProductCode (a Packed GUID of ProductCode), the
' PackageCode and the UpgradeCode of the MSI. Much quicker than getting these
' out of the MSI's the Manual Way.
References:
http://msdn.microsoft.com/en-us/library/aa369794%28VS.85%29.aspx
http://www.eggheadcafe.com/forumarchives/platformsdkmsi/Jan2006/post25948124.asp
if wscript.arguments.count = 0 then
MSIs = inputbox("Enter in * delimited list of MSI's to query (Max 254 characters)", "MSI Product Details")
MSIs = split(MSIs,"*")
else
set MSIs = wscript.arguments
end if
set objFS = createobject("scripting.filesystemobject")
For Each MSIPath in MSIs
if objFS.fileexists(MSIPath) then
Set MSIDetails = EvaluateMSI(MSIPath)
MSIDetails = MSIPath & ": " & vbcrlf & vbcrlf & "Product Name: " &_
MSIDetails("ProductName") & vbcrlf & "Product Code: " &_
MSIDetails("ProductCode") & vbcrlf & "Product Key : " &_
"HKCR\Installer\Products\" & PackGUID(MSIDetails("ProductCode")) &_
vbcrlf & "Package Code: " & MSIDetails("PackageCode") & vbcrlf &_
"Upgrade Code: " & MSIDetails("UpgradeCode") & vbcrlf
WScript.Echo MSIDetails
else
wscript.echo "Inaccessible; Non-existant; or Error in Path for:" & vbcrlf & MSIPath & vbcrlf & "... skipping"
end if
Next
Function EvaluateMSI(MSIPath)
On Error Resume Next
' create installer object
Set oInstaller = CreateObject("WindowsInstaller.Installer")
' open msi in read-only mode
Set oDatabase = oInstaller.OpenDatabase(MSIPath, 0)
Set objDictionary = CreateObject("Scripting.Dictionary")
' Get Package Code from Summary Information Stream
Set streamobj = oDatabase.SummaryInformation(0) '0 = read only
objDictionary("PackageCode") = streamobj.Property(9)
' Get Product Name from MSI Database
Set View = oDatabase.OpenView("Select `Value` From Property WHERE `Property`='ProductName'")
View.Execute
Set ProductName = View.Fetch
objDictionary("ProductName") = ProductName.StringData(1)
' Get Product Code from MSI Database
Set View = oDatabase.OpenView("Select `Value` From Property WHERE `Property`='ProductCode'")
View.Execute
Set ProductCode = View.Fetch
objDictionary("ProductCode") = ProductCode.StringData(1)
' Get Upgrade Code from MSI Database
Set View = oDatabase.OpenView("Select `Value` From Property WHERE `Property`='UpgradeCode'")
View.Execute
Set UpgradeCode = View.Fetch
objDictionary("UpgradeCode") = UpgradeCode.StringData(1)
Set EvaluateMSI = objDictionary
On Error Goto 0
End Function
Function PackGUID(guid)
PackGUID = ""
'*
Dim temp
temp = Mid(guid,2,Len(guid)-2)
Dim part
part = Split(temp,"-")
Dim pack
pack = ""
Dim i, j
For i = LBound(part) To UBound(part)
Select Case i
Case LBound(part), LBound(part)+1, LBound(part)+2
For j = Len(part(i)) To 1 Step -1
pack = pack & Mid(part(i),j,1)
Next
Case Else
For j = 1 To Len(part(i)) Step 2
pack = pack & Mid(part(i),j+1,1) & Mid(part(i),j,1)
Next
End Select
Next
'*
PackGUID = pack
End Function
If one needs to copy&paste any of the GUID's in the popup, I tend to find it easiest to use a subsequent inputbox, like inputbox "","",MSIDetails
IMPORTANT: It's been a while since this answer was originally posted, and smart people came up with wiser answers. Check How can I find the Upgrade Code for an installed MSI file? from @ Stein Åsmul if you need a solid and comprehensive approach.
Here's another way (you don't need any tools):
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
key (if it's a 32-bit installer on a 64-bit machine, it might be under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
instead).This GUID you stopped on is the ProductCode.
Now, if you're sure that reinstallation of this application will go fine, you can run the following command line:
msiexec /i {PRODUCT-CODE-GUID-HERE} REINSTALL=ALL REINSTALLMODE=omus /l*v log.txt
This will "repair" your application. Now look at the log file and search for "UpgradeCode". This value is dumped there.
NOTE: you should only do this if you are sure that reinstall flow is implemented correctly and this won't break your installed application.
In Windows 10 preview build with PowerShell 5, I can see that you can do:
$info = Get-Package -Name YourInstalledProduct
$info.Metadata["ProductCode"]
Not familiar with even not sure if all products has UpgradeCode, but according to this post you need to search UpgradeCode from this registry path:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes
Unfortunately, the registry key values are the ProductCode and the registry keys are the UpgradeCode.
If anyone wants to get installed application package code, just execute below command with your application name in the command prompt. You will be getting product code along with package code.
wmic product where "Name like '%YOUR_APPLICATION_NAME%'" get IdentifyingNumber, PackageCode
Another way-too-complicated workaround, with the benefit of not having to re-install the application as the previous workaround required. This requires that you have access to the msi (or a setup.exe with the msi embedded).
If you have Visual Studio 2012 (or possibly other editions) and install the free "InstallShield LE", then you can create a new setup project using InstallShield.
One of the configuration options in the "Organize your Setup" step is called "Upgrade Paths". Open the properties for Upgrade Paths, and in the left pane right click "Upgrade Paths" and select "New Upgrade Path" ... now browse to the msi (or setup.exe containing the msi) and click "open". The upgrade code will be populated for you in the settings page in the right pane which you should now see.
It takes some time to return results, easily many tens of seconds, but wmic works well and can be scripted:
wmic product where "Name like '%Word%'" get Name, Version, IdentifyingNumber
result:
IdentifyingNumber Name Version
{90140000-001B-0409-0000-0000000FF1CE} Microsoft Office Word MUI (English) 2010 14.0.6029.1000
The IdentifingNumber
is the ProductCode. I didn't see a property for UpgradeCode, but perhaps it might be buried under something else. See http://quux.wiki.zoho.com/WMIC-Snippets.html for many other examples, including uninstall:
wmic path win32_product where "name = 'HP Software Update'" call Uninstall