I use this function to find any installed application.
But the parameter “InstallLocation” doesn’t work at all.
Any clue?
Thanks!!
void FindApplication(string appName)
{
StringBuilder sbProductCode = new StringBuilder(39);
int iIdx = 0;
while (0 == MsiEnumProducts(iIdx++, sbProductCode))
{
Int32 productNameLen = 512;
StringBuilder sbProductName = new StringBuilder(productNameLen);
MsiGetProductInfo(sbProductCode.ToString(), "ProductName", sbProductName, ref productNameLen);
if (sbProductName.ToString().Contains(appName))
{
Int32 installDirLen = 2048;
StringBuilder sbInstallDir = new StringBuilder(installDirLen);
MsiGetProductInfo(sbProductCode.ToString(),"InstallLocation", sbInstallDir, ref installDirLen);
string result = string.Format("ProductName {0}: {1}", sbProductName, sbInstallDir);
}
}
}
I’ve visited the following links, and they don’t appear to be outdated:
The only keys I see that can be used are these:
I should point out that it appears
MsiGetProductInfoEx(second link) should be used to gather information on published/installed products added by another user; and requires administrative privledges.