windows-installer - 如何获得msp版本?
问题描述
我需要获取 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 它不起作用。有任何想法吗?
解决方案
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
表。
推荐阅读
- javascript - 有没有办法在浏览器 javascript 中执行或模拟忙/等待样式输入?
- c++ - 客户端 C++ 程序的分段错误
- powershell - 从数字列表构建表达式
- python - 返回类而不改变任何东西
- javascript - json-editor 忽略起始值
- html - 获取动态填充下拉列表的旧选定值
- java - 如何生成唯一值数组
- javascript - 尝试使用 pkg 制作 Typescript + NodeJS 应用程序的二进制文件时出现错误“无法读取文件,ENOENT node:util”
- reactjs - 防止在特定 RTK 查询端点上缓存
- java - 当使用 Saxon 的 XSLT 引擎处理 XML 时,如何将我的 XSL 文件指向它需要的 XSD 文件?