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;
}
{
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。
本文介绍了一种使用C#代码从MSI安装包中读取产品代码的方法。通过调用Windows Installer组件,创建数据库视图并执行查询,可以准确地获取ProductCode。需要注意的是,必须添加对msi.dll的引用。
2237

被折叠的 条评论
为什么被折叠?



