【发布时间】:2020-11-25 03:51:51
【问题描述】:
我正在尝试使用命令行(通过 PsExec)配置 autologon.exe。但是,密码中的特殊字符会导致问题。
给定这个密码:I'vegotspe"cia"char@ters
此命令有效:
Start-Process 'C:\Autologon.exe' -ArgumentList 'username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula'
但是,由于我使用的是 PsExec,因此我需要使用“/c”进行调用,所以我有以下命令。
powershell.exe /c "Start-Process 'C:\Autologon.exe' -ArgumentList 'username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula'"
此命令不会输出任何错误,但也不起作用。如果我没有双引号字符,它可以工作。知道我该如何完成这项工作吗?
我正在使用PyPsexec,所以一旦我得到上述命令;调用看起来像这样
c.run_executable("powershell.exe", arguments=''' /c Start-Process 'C:\Autologon.exe' -ArgumentList 'username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula' ''')
更新 1: 刚刚按照@lit 的建议尝试了 EncodedCommand,但我似乎遇到了同样的语法问题,因为它需要用引号括起来。
命令:
[Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("Start-Process 'C:\Autologon.exe' -ArgumentList 'username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula'"))
输出:
ine:1 char:140
+ ... ess 'C:\Autologon.exe' -ArgumentList 'username','hostname','"I''vegot ...
+ ~
Missing ')' in method call.
At line:1 char:140
+ ... username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula'"))
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'I''vegotspe\"cia\"char@ters"','/accepteula'"' in expression or statement.
At line:1 char:184
+ ... username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula'"))
+ ~
Unexpected token ')' in expression or statement.
At line:1 char:185
+ ... username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula'"))
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndParenthesisInMethodCall
【问题讨论】:
-
/c参数是-Command。目前尚不清楚psexec是如何使用的。这是来自 SysInternals 工具包的psexec吗?为什么使用psexec和powershell?另请参阅 powershell-EncodedCommand参数。 -
它与 PsExec 相同,但存在一个 python 库 (PyPsExec) 以使其更容易合并到脚本中。使用 PsExec 以便我可以远程执行此命令,而 Powershell 用于调用 Autologin。
-
刚刚尝试了编码命令(用结果更新了原始问题)
-
那么目标是 Windows 框吗?或者来源,我想。你有什么理由不只是做一个远程
Invoke-Command?
标签: python powershell cmd psexec