原文 http://www.alteridem.net/2008/05/20/read-properties-from-an-msi-file/
It took a fair amount of searching and code tweaking, but I finally worked it all out.
- Add a reference to the COM Microsoft Windows Installer Object Library.
- Add a using WindowsInstaller;
- Add the following static method to your code (error checking removed for brevity.)
public static string GetMsiProperty(string msiFile, string property)
{
string retVal = string.Empty;
// Create an Installer instance
Type classType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
Object installerObj = Activator.CreateInstance(classType);
Installer installer = installerObj as Installer;
// Open the msi file for reading
// 0 - Read, 1 - Read/Write
Database database = installer.OpenDatabase(msiFile, 0);
// Fetch the requested property
string sql = String.Format("SELECT Value FROM Property WHERE Property='{0}'", property);
WindowsInstaller.View view = database.OpenView(sql);
view.Execute(null);
// Read in the fetched record
Record record = view.Fetch();
if (record != null)
retVal = record.get_StringData(1);
view.Close();
return retVal;
}
4.使用
GetMsiProperty(openFileDialog1.FileName, "ProductVersion");
另外还有差不多的一篇:
http://www.codeproject.com/KB/install/Read_MSI.aspx
浙公网安备 33010602011771号