You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何向PsExec传递含空格的"Program Files"路径?已尝试多种方法未果

解决PsExec传递含空格路径的问题

你遇到的问题确实是路径中的空格导致解析错误——PowerShell调用外部命令时,外层双引号会被解析去除,传到远程cmd时,C:\Program Files被空格拆分成了两个部分,从而报错。以下是几种可行的解决方法:

方法1:嵌套双引号转义

在PowerShell中,连续两个双引号会被解析为一个双引号传递给PsExec,确保远程cmd收到带引号的完整路径:

$computers=Get-Content -Path "C:\tmp\computers.txt"

foreach ($computer in $computers){
    psexec64.exe \\$computer -h -u admin -p passW0rd cmd /c ""C:\Program Files\uninstall\uninstall.bat --force""
}

方法2:单引号包裹cmd命令字符串

用单引号保留整个cmd命令的原始格式,内部路径用双引号包裹:

$computers=Get-Content -Path "C:\tmp\computers.txt"

foreach ($computer in $computers){
    psexec64.exe \\$computer -h -u admin -p passW0rd cmd /c '"C:\Program Files\uninstall\uninstall.bat --force"'
}

方法3:使用Windows 8.3短路径

将C:\Program Files替换为对应的短路径C:\PROGRA~1,避免空格问题:

$computers=Get-Content -Path "C:\tmp\computers.txt"

foreach ($computer in $computers){
    psexec64.exe \\$computer -h -u admin -p passW0rd cmd /c "C:\PROGRA~1\uninstall\uninstall.bat --force"
}

方法4:用PowerShell调用操作符&配合参数包裹

使用&调用外部命令,配合引号明确参数边界:

$computers=Get-Content -Path "C:\tmp\computers.txt"

foreach ($computer in $computers){
    & psexec64.exe "\\$computer" -h -u admin -p passW0rd cmd /c '"C:\Program Files\uninstall\uninstall.bat --force"'
}

内容的提问来源于stack exchange,提问作者Arbelac

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 17:13:35