Friday, October 23, 2015

PInvoke for finding all MSI locations of installers with a specific UpgradeCode

class Program { /* References http://www.pinvoke.net/default.aspx/msi/MsiEnumRelatedProducts.html http://stackoverflow.com/questions/3475793/how-to-find-program-location-in-registry-if-i-know-msi-guid */ static void Main(string[] args) { string upgradeCode = "{CC6ED12E-5384-4C17-A293-D6D19371A5E8}"; StringBuilder sbProductCode = new StringBuilder(39); int iIndex = 0; while (0 == MsiEnumRelatedProducts(upgradeCode, 0, iIndex++, sbProductCode)) { Int32 len = 512; StringBuilder builder = new StringBuilder(len); MsiGetProductInfo(sbProductCode.ToString(), "LocalPackage", builder, ref len); Console.WriteLine(builder.ToString()); } Console.ReadLine(); } [DllImport("msi.dll", CharSet = CharSet.Unicode)] static extern Int32 MsiGetProductInfo(string product, string property, [Out] StringBuilder valueBuf, ref Int32 len); [DllImport("msi.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern UInt32 MsiEnumRelatedProducts(string strUpgradeCode, int reserved, int iIndex, StringBuilder sbProductCode); }

No comments:

Post a Comment

There was an error in this gadget