Detect if a MSI component is installed#
A C# program for those who don’t know MSI SDK or C++. C++ programmers can find the API inside the msi.h file in Windows SDK.
static class Program
{
static int Main(string[] args)
{
uint pathSize = 0;
try
{
foreach (string componentId in args)
{
MsiInstallState state = MsiLocateComponent(
componentId, null, ref pathSize);
if (state != MsiInstallState.Local)
{
return ERROR_UNKNOWN_COMPONENT;
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return ERROR_MOD_NOT_FOUND;
}
return 0;
}
[`DllImport ("msi.dll", CharSet = CharSet.Auto)]
extern static internal MsiInstallState MsiLocateComponent(string component, string path, ref uint pathSize);
/// Enumeration of MSI install states.
internal enum MsiInstallState: int
{
Local = 3
}
const int ERROR_MOD_NOT_FOUND = 126;
const int ERROR_UNKNOWN_COMPONENT = 1607;
}
}
Hard Drive Broke
MFC Feature Pack发布