哪个符号是cmd中的转义字符



我有这个代码:

powershell -command "& { (New-Object Net.WebClient).DownloadFile('linkToMyFile.file', 'C:my.file') }"

它用于下载文件。
当我在远程服务器上的cmd中执行它时 - 一切都很好。
但是当我想使用 paexec 从远程服务器上的计算机执行此代码时,我在转义字符方面遇到了一些麻烦。
我的 CMD 中的命令:

psexec.exe \remoteServer.0.1 -u username -p password -dbg -lo D:PsExec.log cmd /c "powershell -command "& { (New-Object Net.WebClient).DownloadFile('linkToMyFile.file', 'C:my.file') }""

我尝试使用^符号,但相同的错误;
使用 ^ 符号作为双引号的代码:

psexec.exe \remoteServer.0.1 -u username -p password -dbg -lo D:PsExec.log cmd /c "powershell -command ^"& { (New-Object Net.WebClient).DownloadFile('linkToMyFile.file', 'C:my.file') }^""

另外,我尝试使用(如在PHP中(进行转义,但结果相同。
帮助解决此问题或提供有关如何使用命令行远程下载文件的建议。

不幸的是,

CMD根据转义的内容和位置使用不同的转义字符。没有一个转义字符可以在任何地方使用。

在大多数情况下,下一个字符是通过在它前面加上插入符号(^(来转义的,例如在for /f循环中:

for /f "tokens=1" %%a in ('type file.txt ^| find "something"') do ...

但有时字符通过加倍来转义,例如批处理脚本中的百分比字符 ( % (:

@echo off
echo %%DATE%%=%DATE%

有时你甚至可能需要输入其他转义字符(如反斜杠(,因为你需要转义的东西不是为了CMD,而是为了字符串被传递给的命令:

mountvol | findstr /r \\

不过,您的特定方案不应需要额外的引号或转义。只需直接运行PowerShell命令行,无需cmd /c

paexec.exe \remoteServer.0.1 -u username -p password powershell -command "&{...}"

是否可以完整地使用Powershell?如果是这样,您可以尝试以下操作:

New-PsDrive -Name X -Root \127.0.0.1c$ -PsProvider FileSystem -Credential (Get-Credential)
Copy-Item -Path X:RequestedFile.txt -Destination C:Temp
Remove-PsDrive -Name X

如果您的目的地是http地址,您可以执行以下操作:

Invoke-WebRequest -Uri http://some.uri -Method Get -OutFile C:tempmyfile -Credential (Get-Credential)

希望有帮助

取而代之的是:

psexec.exe \remoteServer.0.1 -u username -p password -dbg -lo D:PsExec.log cmd /c "powershell -command "& { (New-Object Net.WebClient).DownloadFile('linkToMyFile.file', 'C:my.file') }""

这样做:

psexec.exe \remoteServer.0.1 -u 'username' -p 'password' powershell.exe -Command "& {(New-Object System.Net.WebClient).DownloadFile('linkToMyFile.file', 'C:my.file')}"

这应该可以完成您的工作。

希望对您有所帮助。

最新更新