We\'re currently using a GUID to identify the application when running our uninstall script which contains msiexec. The problem I\'m having is the GUID changes every time I
What do you know that doesn't change, or that does change but you can easily track?
Say the product code changes, but the upgrade code doesn't. You could follow PhilDW's suggestions to retrieve a product code from that upgrade code using MsiEnumRelatedProducts or Installer.Related or equivalent.
Say the name doesn't stays the same. You could follow Stein's suggestions to find the product code by product name, starting with MsiEnumProductsEx or Installer.ProductsEx or equivalent.
Say you cache a local copy of the installing .msi's in an unchanging location, or one easily found by your script. You could follow 4c74356b41's suggestion to use that path in a command line to msiexec. (Note that msiexec /x accepts either a package path or a product code.)
Say you don't like any of those options. Perhaps you can add a registry value in HKEY_LOCAL_MACHINE\Software\YourCompany\YourProduct, setting a string value ProductCode to [ProductCode]
. Then you can use reg query HKLM\Software\YourCompany\YourProduct /v ProductCode
, or equivalent (sorry, I'm a dunce with PowerShell), to fetch the current product code. (At least if you account for 32-bit vs 64-bit paths, of course.)