首页 > 解决方案 > msiexec 没有对提供的路径进行精确处理

问题描述

这个问题在这里已经讨论过了,但没有给出明确的答案,所以再次提出。

我正在尝试提取 .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
}

一旦被调用,我就会弹出窗口。请看一下所附的截图在此处输入图像描述

并且没有提取 .msi 文件。

标签: powershellwindows-installer

解决方案


1.转义:PowerShell中的转义字符是重音 ` ASCII:96, Unicode:U + 0060 - 我认为)。重音在编程中的使用。尝试如下逃脱:

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

2.“停止解析”PSv3+提供--%停止解析符号更多来自ss64.com)。它将命令行的其余部分按原样传递给外部实用程序,以保存 %...% 样式环境变量的潜在扩展:

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

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


其他链接


推荐阅读