我正在使用Powershell从MSI文件中提取信息,我已经找到了这样做的例子,但它们都是特定于值的E,G如果您知道该属性的名称,您可以找到该属性的值我想在哪里找到所有属性,它实际上是我需要的快捷方式表中的信息,下面是我想要实现的内容。
function Get-MsiDatabaseVersion {
param (
[IO.FileInfo] $FilePath
)
try {
$windowsInstaller = New-Object -com WindowsInstaller.Installer
$database = $windowsInstaller.GetType().InvokeMember(
"OpenDatabase", "InvokeMethod", $Null,
$windowsInstaller, @($FilePath.FullName, 0)
)
$q = "SELECT Directory_ FROM Shortcut"
$View = $database.GetType().InvokeMember(
"OpenView", "InvokeMethod", $Null, $database, ($q)
)
$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
$record = $View.GetType().InvokeMember(
"Fetch", "InvokeMethod", $Null, $View, $Null
)
$productVersion = $record.GetType().InvokeMember(
"StringData", "GetProperty", $Null, $record, 1
)
$View.GetType().InvokeMember("Close", "InvokeMethod", $Null, $View, $Null)
return $productVersion
} catch {
throw "Failed to get MSI file version the error was: {0}." -f $_
}
}
Get-MsiDatabaseVersion" C:\ Random.msi"
所以其中$ q =" SELECT Directory_ FROM Shortcut"我需要知道快捷方式表中所有行的名称才能找到所有目录。目前它只返回第一个值。 如果你能帮助我,我非常感激。 谢谢
答案 0 :(得分:0)
要了解MSI的属性,您可以在Ocra中打开它。我拿了你的代码并添加了一个循环,请将问题标记为正确,如果它对你有所帮助。
function Get-MsiDatabaseVersion {
param (
[IO.FileInfo] $FilePath
)
try {
$windowsInstaller = New-Object -com WindowsInstaller.Installer
$database = $windowsInstaller.GetType().InvokeMember(
"OpenDatabase", "InvokeMethod", $Null,
$windowsInstaller, @($FilePath.FullName, 0)
)
$q = "SELECT Directory_ FROM Shortcut"
$View = $database.GetType().InvokeMember(
"OpenView", "InvokeMethod", $Null, $database, ($q)
)
$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
$record = $View.GetType().InvokeMember(
"Fetch", "InvokeMethod", $Null, $View, $Null
)
while($record -ne $null)
{
$shortcut = $record.GetType().InvokeMember(
"StringData", "GetProperty", $Null, $record, 1
)
$shortcut
$record = $View.GetType().InvokeMember(
"Fetch", "InvokeMethod", $Null, $View, $Null
)
}
$View.GetType().InvokeMember("Close", "InvokeMethod", $Null, $View, $Null)
#return $shortcut
} catch {
throw "Failed to get MSI file version the error was: {0}." -f $_
}
}
Get-MsiDatabaseVersion -FilePath .\Setup1.msi
答案 1 :(得分:0)
您可能需要查看:
Windows Installer PowerShell Module
作者是MSFT MSI专家,他的cmdlet比使用WindowsInstaller.Installer对象进行COM Interop要清晰得多。
get-msiproperty Product*, UpgradeCode -path example.msi
get-msitable .\example.msi -query "SELECT ComponentId, FileName, File.Attributes FROM Component, File WHERE Component_ = Component" | where-object { $_.'File.Attributes'.HasVital }