简体   繁体   中英

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

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.

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

$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. [1]: http://www.scconfigmgr.com/2014/08/22/how-to-get-msi-file-information-with-powershell/

从 MSI 包中获取 ProductCode 的更短方法:

Get-AppLockerFileInformation -Path "C:\PathTo\my.msi" | select -ExpandProperty Publisher | Select BinaryName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM