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。
|
请发表评论