What are ProductCode & UpgradeCode & GUID? How to detect if certain application/library is already installed on the user machine?

11,587

Solution 1

UpgradeCode denotes a product with different versions.

ProductCode denotes a version of a product.

For example, theoretically there is one ProductCode for Microsoft Word 2003 and a different one for Word 2007. However both Word 2003 and 2007 would share the same UpgradeCode since you can upgrade from one to the other.

GUID simply means Globally Unique Identifier. It's a large string of numbers and letters that should be unique on the planet.

UpgradeCodes and ProductCodes are kept in the Registry, but they're hidden and encrypted and you'll need to use a tool to query them. For example:

MsiGetProductInfo(ProductCode, INSTALLPROPERTY_VERSIONSTRING, lpVerName, &cchVerName);
MsiEnumRelatedProducts(UpgradeCode, 0, 0, ProductCode);

To check and see if a product is already installed on a user's machine you might use MsiEnumRelatedProducts() as above. I think you're asking more than what can be answered in a StackOverflow answer. Consider studying more about MSI:

MSDN section on Windows Installer

Solution 2

The ProductCode and UpgradeCode GUIDs identify your software. Together with a third code, the PackageCode.

Additionally to the mentioned clean API way, of course it is possible to detect these codes in the registry too. In some places they are a little bit "changed" this is true, but this is no encryption, only number reordering, e.g. under HKCR\Installer. Quite easy to decipher and I think there is example code anywhere in the net. A 10 liner or so.

In a "unencrypted" way you can find the ProductCode of installed software here:

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
(But beware, there are two other keys for user-specific and 32 bit WOW software on 64 bit machines).

It is not recommended to detect applications using their codes, because these can change in the case of updates. If using one, UpgradeCode is safer, because it changes less, but not safe enough. Look for registry paths containing company names and versions of your software!

More knowledge:
The ProductCode is the main identity of a MSI setup. Thumb rules for these codes (ProductCode, UpgradeCode) for setup authors are:

  1. Don't change any of them if you are doing an update by a patch.

  2. If you want to do a full update containing all files, do a socalled Major Upgrade.
    (There are other possibilities, but this is the most comfortable one, especially for beginners). a) Change your ProductCode for Major Upgrades.

  3. Don't change the UpgradeCode for ANY upgrade, except you want that the new version can be installed in parallel to the old one. In MSI "thinking" then it is a completely new product (better understandable as upgrade path/tree).

  4. If you change the UpgradeCode, always change the ProductCode

  5. Normally don't care about the PackageCode. A good build tool changes it with ever build to a random new GUID. To do a an install test with that build it may be necessary to uninstall the old built version first or to know more about MSI (here: Small/Minor Upgrades).

Share:
11,587
claws
Author by

claws

Updated on June 05, 2022

Comments

  • claws
    claws almost 2 years

    I've already gone through:

    Check if the application is already installed

    Detecting if a program is already installed with NSIS

    http://nsis.sourceforge.net/Add_uninstall_information_to_Add/Remove_Programs

    My questions are little more in depth and little more general.

    So, as you understood my problem is that I want to check if "Certain Applications" are already installed on the user's machine? I'm generating the installer using Advanced Installer.

    First few questions:

    • What is Upgrade Code? Advanced installer has option, Product Version (identify by Upgrade Code)
    • What is Product Code? Advanced installer Product Version (identify by Product Code)
    • Component is installed : GUID. What is GUID?

    All the above three has values like this:

    {49EB7A6A-1CEF-4A1E-9E89-B9A4993963E3} I don't know what these values are but it seems that computer is recognizing software using this kind of strange ID.

    My required applications are

    1. MySQL DBMS
    2. MySQL .NET Connector

    One fact that I discovered is Upgrade Code & Product Code can be extracted from its "msi installer". So, I extracted these values from the installers & registry.

    MySQL Server

    Installer = mysql-5.1.43-win32.msi 
    Upgrade Code = {49EB7A6A-1CEF-4A1E-9E89-B9A4993963E3}
    Product Code = {0ECED7D8-FF53-4DC9-958E-C2177F528DE4}
    GUID (for component Installed) = ????
    Uninstall Path = HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{0ECED7D8-FF53-4DC9-958E-C2177F528DE4}
    
    Installer = mysql-5.1.46-win32.msi
    Upgrade Code = {49EB7A6A-1CEF-4A1E-9E89-B9A4993963E3}
    Product Code = {EA8FDE5A-2B33-4EDD-B7E7-8D179DF731A5}
    GUID (for component Installed) = ????
    Uninstall Path = HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{EA8FDE5A-2B33-4EDD-B7E7-8D179DF731A5}
    
    Installer = mysql-essential-5.1.46-win32.msi
    Upgrade Code = {49EB7A6A-1CEF-4A1E-9E89-B9A4993963E3}
    Product Code = {AD33AF2C-6485-4106-B012-1D9CDC88A454}
    GUID (for component Installed) = ????
    Uninstall Path = HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AD33AF2C-6485-4106-B012-1D9CDC88A454}
    
    Installer = mysql-essential-5.0.89-win32.msi
    Upgrade Code = {49EB7A6A-1CEF-4A1E-9E89-B9A4993963E3}
    Product Code = {9A4DA7EF-A7B9-4282-90AD-10976AA24E69}
    GUID (for component Installed) = ????
    Uninstall Path = HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9A4DA7EF-A7B9-4282-90AD-10976AA24E69}
    

    Observation from above data:

    • UpgradeCode of a software is constant & is irrespective of its version. But surprisingly there is no single entry in the registry with the value of UpgradeCode
    • ProductCode is version specific & it is used by the MSI internally which is actually reasonable because. MSI allows applications of different versions to be installed side by side.
    • I don't know how to find GUID.

    MySQL ADO .NET Driver

    Installer = mysql.data.5.2.5.msi
    Upgrade Code = --- 
    Product Code = {5FD88490-011C-4DF1-B886-F298D955171B}
    GUID (for component Installed) = ????
    
    Installer = mysql.data.6.2.2.msi
    Upgrade Code = ---
    Product Code = {5FD88490-011C-4DF1-B886-F298D955171B}
    GUID (for component Installed) = ????
    UninstallPath =HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5FD88490-011C-4DF1-B886-F298D955171B}
    Installer =  mysql.data.6.2.3.msi
    Upgrade Code = ---
    Product Code = {5FD88490-011C-4DF1-B886-F298D955171B}
    GUID (for component Installed) = ????
    

    Observations from above data:

    • surprisingly, it couldn't find UpgradeCode from installer of mysql.data.*.msi. I wonder why? This contradicts with my above observation.
    • ProductCode for all different versions is same here. This again contradicts my above observations.
    • I still don't know how to find GUID.

    Now,

    • What exactly are these ProductCode & UpgradeCode & GUID.
    • Which denotes what?
    • Why are above observations contradicting?
    • I don't care about versions. I don't want to depend on Application Name then how do I check if MySQL driver & MySQL ADO .NET.
    • Does detection become simple if they are .NET assemblies? How to do then? I don't want to ship the assemblies with my deployed files.