0

我需要获取 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 它不起作用。有任何想法吗?

4

1 回答 1

0

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();
}

它应该包含那里列出的补丁表。MSP 文件中可能不包含Property表。

于 2021-10-12T07:04:24.633 回答