Question

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 to get the UpgradeCode and ProductCode of this installed application. I feel there must be some tool for this.

Can anyone kindly let me know how to get the UpgradeCode and ProductCode of an installed application?

Was it helpful?

Solution


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

  • open system registry and search for 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).
  • the GUIDs listed under that key are the products installed on this machine
  • find the one you're talking about - just step one by one until you see its name on the right pane

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.

OTHER TIPS

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

To everyone using:

Get-WMIObject win32_product

You should be aware that this will run a self-heal on every single MSI application installed on the PC. If you were to check eventvwr it will say it has finished reconfiguring each product.

In this case i use the following (a mixture of Yan Sklyarenko's method):

$Reg = @( "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" )
$InstalledApps = Get-ItemProperty $Reg -EA 0
$WantedApp = $InstalledApps | Where { $_.DisplayName -like "*<part of product>*" }

Now if you were to type:

$WantedApp.PSChildName

You would be given the following:

PS D:\SCCM> $WantedApp.PSChildName
{047904BA-C065-40D5-969A-C7D91CA93D62}

If your organization uses loads of MST's whilst installing applications you would want to avoid running self-heals encase they revert some crucial settings.

  • Note - This will find your product code, then the upgrade can be found as Yan mentioned. I usually, though, just use either 'InstEd It!' or 'Orca' then go to the Property table of the MSI and it lists them right at the top.

If you have msi installer open it with Orca (tool from Microsoft), table Property (rows UpgradeCode, ProductCode, Product version etc) or table Upgrade column Upgrade Code.

Try to find instller via registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall find required subkey and watch value InstallSource. Maybe along the way you'll be able to find the MSI file.

Powershell handles tasks like this fairly handily:

$productCode = (gwmi win32_product | `
                ? { $_.Name -Like "<PRODUCT NAME HERE>*" } | `
                % { $_.IdentifyingNumber } | `
                Select-Object -First 1)

You can then use it to get the uninstall information as well:

$wow = ""
$is32BitInstaller = $True # or $False

if($is32BitInstaller -and [System.Environment]::Is64BitOperatingSystem) 
{
    $wow = "\Wow6432Node" 
}

$regPath = "HKEY_LOCAL_MACHINE\SOFTWARE$wow\Microsoft\Windows\CurrentVersion\Uninstall"

dir "HKLM:\SOFTWARE$wow\Microsoft\Windows\CurrentVersion\Uninstall" | `
? { $_.Name -Like "$regPath\$productCode"  }

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.

You can use the MsiEnumProductsEx and MsiGetProductInfoEx methods to enumerate all the installed applications on your system and match the data to your application

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.

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

If you don't have the msi and you need the upgrade code, rather than the product code then the answer is here: How can I find the upgrade code for an installed application in C#?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top