msiexec未对提供的路径进行严格限制

问题描述 投票:0回答:1

这里已经讨论了这个问题,但是最终没有得到明确的答案,因此再次提出。

我正尝试如下提取.msi文件的内容:

function script:Export-MsiContents
{
[CmdletBinding()]
param
(
    [Parameter(Mandatory = $true, Position = 0)]
    [ValidateNotNullOrEmpty()]
    [ValidateScript({Test-Path $_})]
    [ValidateScript({$_.EndsWith(".msi")})]
    [String] $MsiPath,

    [Parameter(Mandatory=$false, Position = 1)]
    [String] $TargetDirectory
)

if(-not($TargetDirectory))
{
    $currentDir = [System.IO.Path]::GetDirectoryName($MsiPath)
    Write-Warning "A target directory is not specified. The contents of the MSI will be extracted to the location, $currentDir\Temp"

    $TargetDirectory = Join-Path $currentDir "Temp"
}

$MsiPath = Resolve-Path $MsiPath

Write-Verbose "Extracting the contents of $MsiPath to $TargetDirectory"
Start-Process "MSIEXEC" -ArgumentList "/a $MsiPath /qn TARGETDIR=$TargetDirectory" -Wait -NoNewWindow
}

一旦打电话,我就会弹出窗口。请查看所附的屏幕截图enter image description here

并且没有.msi文件的提取。

powershell msiexec
1个回答
0
投票

1。转义:PowerShell中的转义字符是重音符号:`。尝试如下逃脱:

Start-Process "MSIEXEC" -ArgumentList "/a `"C:\my setup.msi`" /qn TARGETDIR=`"C:\Extract here`"" -Wait -NoNewWindow

2。 “停止解析”PSv3+提供--%the stop-parsing symbol。它将其余命令行原样传递给外部实用程序,但可能会扩展%...%样式的环境变量:

# Everything after --% is passed as-is.
msiexec --% /a "C:\my setup.msi" /qn TARGETDIR="C:\Extract here"

我不是Powershell专家。以上基于:


其他链接

© www.soinside.com 2019 - 2024. All rights reserved.