[DllImport("msi.dll",
EntryPoint="MsiEnumProductsExW",
CharSet = CharSet.Unicode,
ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern uint MsiEnumProductsEx(
string szProductCode,
string szUserSid,
uint dwContext,
uint dwIndex,
string szInstalledProductCode,
out object pdwInstalledProductContext,
string szSid,
ref uint pccSid)
public enum MSIINSTALLCONTEXT
{
MSIINSTALLCONTEXT_NONE = 0,
MSIINSTALLCONTEXT_USERMANAGED = 1,
MSIINSTALLCONTEXT_USERUNMANAGED = 2,
MSIINSTALLCONTEXT_MACHINE = 4,
MSIINSTALLCONTEXT_ALL = (MSIINSTALLCONTEXT_USERMANAGED | MSIINSTALLCONTEXT_USERUNMANAGED | MSIINSTALLCONTEXT_MACHINE),
}
Do you know one? Please contribute it!
Please add some!
public static bool FindByProductCode(Guid productCode, ref string productName)
{
try
{
string codeToFind = productCode.ToString("B").ToUpper();
var code = new string(new char[40]);
object junk = null;
string szSid = new string(new char[300]);
uint pccSid = 300;
uint res = MsiInterop.MsiEnumProductsEx(codeToFind, null, (uint)MsiInterop.MSIINSTALLCONTEXT.MSIINSTALLCONTEXT_USERUNMANAGED, 0, code, out junk, szSid, ref pccSid);
if (res == 0)
{
uint valueSize = 1024;
var valueProductName = new string(new char[valueSize]);
MsiInterop.MsiGetProductInfo(code, MsiInstallerProperty.ProductName, valueProductName, ref valueSize);
productName = valueProductName;
return true;
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
return false;
}
}