我需要得到msp文件的版本。对于msi文件,我使用下面的代码:
public static string GetMSIVersion(string MSIPath)
{
try
{
Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");
WindowsInstaller.Installer installer = (WindowsInstaller.Installer)
Activator.CreateInstance(type);
WindowsInstaller.Database db = installer.OpenDatabase(MSIPath, 0);
WindowsInstaller.View dv = db.OpenView("SELECT `Value` FROM `Property` WHERE `Property`='ProductVersion'");
WindowsInstaller.Record record = null;
dv.Execute(record);
record = dv.Fetch();
string str = record.get_StringData(1).ToString();
return str;
}
catch (Exception ex)
{
return "";
}
}但对于msp,它不起作用。有什么想法吗?
发布于 2021-10-12 07:04:25
OpenDatabase时需要指定MSP数据库类型,将0替换为MsiOpenDatabaseMode.msiOpenDatabaseModePatchFile (32)
然后,您可以接收msp内的所有表:
Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
WindowsInstaller.Installer installer = (WindowsInstaller.Installer)Activator.CreateInstance(installerType);
Database database = installer.OpenDatabase(mspPath,
MsiOpenDatabaseMode.msiOpenDatabaseModePatchFile);
View view = database.OpenView("SELECT * FROM `_Tables`");
view.Execute(null);
Record record = view.Fetch();
while (record != null)
{
Console.WriteLine(record.StringData[1]);
record = view.Fetch();
}它应该包含列出there的补丁程序表。MSP文件中不能包含Property表。
https://stackoverflow.com/questions/69204252
复制相似问题