从 PHP 读取 Windows Installer(MSI 文件)属性 [英] Read Windows Installer (MSI file) attributes from PHP

查看:30
本文介绍了从 PHP 读取 Windows Installer(MSI 文件)属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Windows MSI 文件,我需要以编程方式从中读取版本号.我唯一能看到这个版本的地方是文件详细信息的主题:

I have a Windows MSI file, that I need to programmatically read the version number from. The only place I can see this version is within the Subject of the file details:

如果我能以某种方式阅读 Subject 的全部内容就好了,但是有什么办法可以从 PHP 中获得它吗?PHP 正在 IIS Web 服务器中运行,如果这有帮助的话 ;-)

If I somehow can read the entire content of Subject this would be fine but is there any way to get this from PHP? The PHP is running in an IIS web server, if this helps ;-)

stat 对此没有帮助.

我考虑过对文件进行校验和,并且可以做到,但我确实需要真实版本.

I considered doing a checksum of the file, and can do that, but I really need the real version.

推荐答案

目前我无法为此找到本机 PHP 解决方案,因此我通过调用 Powershell 脚本暂时解决了这个问题,因为在那里似乎更容易做到.

For now I am unable to find a native PHP solution for this, so I have temporarily solved this by calling a Powershell script as it seems easier to do in there.

我现在有这个 PHP 代码:$version = exec("powershell.exe -file GetMsiVersion.ps1 MyFile.msi);

I am now having this PHP code: $version = exec("powershell.exe -file GetMsiVersion.ps1 MyFile.msi);

根据我上面的图片,$version 将包含 1.5.9,所以我什至不需要解释来自 Subject 的数据.

With my above picture then $version will contain 1.5.9, so I will not even require to interpret the data from Subject.

GetMsiVersion.ps1 Powershell 脚本具有以下代码:

The GetMsiVersion.ps1 Powershell script has this code:

function Get-Property ($Object, $PropertyName, [object[]]$ArgumentList) {
    return $Object.GetType().InvokeMember($PropertyName, 'Public, Instance, GetProperty', $null, $Object, $ArgumentList)
}

function Invoke-Method ($Object, $MethodName, $ArgumentList) {
    return $Object.GetType().InvokeMember($MethodName, 'Public, Instance, InvokeMethod', $null, $Object, $ArgumentList)
}

$Path = $args[0]
$msiOpenDatabaseModeReadOnly = 0
$Installer = New-Object -ComObject WindowsInstaller.Installer
$Database = Invoke-Method $Installer OpenDatabase  @($Path, $msiOpenDatabaseModeReadOnly)
$View = Invoke-Method $Database OpenView  @("SELECT Value FROM Property WHERE Property='ProductVersion'")
Invoke-Method $View Execute
$Record = Invoke-Method $View Fetch
if ($Record) {
    Write-Output (Get-Property $Record StringData 1)
}

Invoke-Method $View Close @()

我会接受这是此时此地的最佳解决方案,但是,我希望这可以从 PHP 本地存档,因为我认为这是一个更好、更干净的解决方案 - 到那时我会接受它作为最佳答案(或者至少不接受我自己的临时解决方案).

I will accept this as the best solution here-and-now but, I hope this can be archieved natively from PHP as I see this as a better and more clean solution - and by then I will accept that as the best answer (or at least unaccept my own temporary solution).

执行 exec 有点邪恶 ;-)

Doing an exec is a little evil ;-)

这篇关于从 PHP 读取 Windows Installer(MSI 文件)属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆