Search code examples
c#.netwindows-installerinstallshieldsetup-project

Read Product Number from Windows Setup Project


I need to get the product number of my setup project which i used InstalledShield for create the .exe.

I read about MsiGetProductInfo() in Installer API, but couldn't find any for applying this in sample code c#.

Thanks.


Solution

  • You're referring to MsiGetProductInfo, so I'll assume that you have a Windows Installer MSI file that your exe installs (because it bootstraps prerequisites) and that you want to get the information after you've installed your setup.

    This is the p/invoke signature:

    DllImport("msi.dll", CharSet=CharSet.Unicode)]
    static extern Int32 MsiGetProductInfo(string product, 
      string property, [Out] StringBuilder valueBuf, ref Int32 len)
    

    and basically the Product is the MSI's ProductCode guid as a string surrounded by {} brackets.

    You haven't posted any code that you may have tried so it's impossible to diagnose whatever issue you may be having. If by "product number" you mean the version, then you use any of the values documented here:

    https://msdn.microsoft.com/en-us/library/windows/desktop/aa370130(v=vs.85).aspx

    where things like INSTALLPROPERTY_VERSIONSTRING are defined in msi.h from a Windows SDK, the value being "VersionString".

    There should be more than enough information in this example also:

    MSI Interop using MSIEnumRelatedProducts and MSIGetProductInfo

    The UpgradeCode usually stays the same for many different ProductCodes as upgrades occur, so the code doesn't change much if you use MsiEnumRelatedProducts on the UpgradeCode to return a ProductCode, and then plug that ProductCode into MsiGetProductInfo.