PowerShell: Get the MSI product code out of a MSI file without installing?

不想你离开。 提交于 2019-12-22 09:32:55

问题


Is there a possibility to retreive the MSI product code out of a MSI file without installing it with PowerShell? I want to compare the product code of a MSI file with the MSI codes installed on a maschine to find out if the file was installed in the past.


回答1:


Here is a script that reads the product code based on this article:

$path = "pathto.msi"

$comObjWI = New-Object -ComObject WindowsInstaller.Installer
$MSIDatabase = $comObjWI .GetType().InvokeMember("OpenDatabase","InvokeMethod",$Null,$comObjWI,@($Path,0))
$Query = "SELECT Value FROM Property WHERE Property = 'ProductCode'"
$View = $MSIDatabase.GetType().InvokeMember("OpenView","InvokeMethod",$null,$MSIDatabase,($Query))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null)
$Record = $View.GetType().InvokeMember("Fetch","InvokeMethod",$null,$View,$null)
$Value = $Record.GetType().InvokeMember("StringData","GetProperty",$null,$Record,1)

$Value now contains the product code.



来源:https://stackoverflow.com/questions/31919064/powershell-get-the-msi-product-code-out-of-a-msi-file-without-installing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!