C# 获取msi文件的ProductCode

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。

posted @ 2011-06-09 15:15  苗 ︶ㄣ  阅读(1005)  评论(1编辑  收藏  举报