C# 获取msi文件的ProductCode
时间:2011-06-09 来源:苗 ︶ㄣ
private string GetProductCode()
{
System.Type oType = System.Type.GetTypeFromProgID("WindowsInstaller.Installer");
Installer inst = System.Activator.CreateInstance(oType) as Installer;
Database DB = inst.OpenDatabase("msi文件完整路径", MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);
string str = "SELECT * FROM Property WHERE Property = 'ProductCode'";
WindowsInstaller.View thisView = DB.OpenView(str);
thisView.Execute();
WindowsInstaller.Record thisRecord = thisView.Fetch();
string result = thisRecord.get_StringData(2);
return result;
}
注意添加WindowsInstaller的引用:c:\windows\sytem32\msi.dll。
相关阅读 更多 +