AutohotKey 中的 Powershell 无法正常工作

Powershell inside AutohotKey is not working

我可以 运行 AHK 文件中的任何 PowerShell 命令。例如,下面的命令:

Run, PowerShell.exe -noexit -Command "Start notepad; start calc.exe",, hide

我有 Powershell 命令,我可以从 PowerShell 运行 它很好地工作,它会在远程机器上将用户添加为本地管理员:

([ADSI]"WinNT://serverabc123/Administrators,Group").Add("WinNT://HMM.org.br/Paul1")

但是,当我在AHK上使用上面的代码时,好像它不起作用!

Run, PowerShell.exe -noexit -Command "([ADSI]"WinNT://serverabc123/Administrators,Group").Add("WinNT://HMM.org.br/Paul1")",, hide

我不断收到此错误:

At line:1 char:8<> + ([ADSI]WinNT://serverabc123/Administrators + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'WinNT://serverabc123/Administrators' in expression or statement.
At line:1 char:8
+ ([ADSI]WinNT://serverabc123/Administrators
+ ~
Missing closing ')' in expression.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken

任何人都可以建议该怎么做吗?我可以写入外部文件 PS1 并从 AHK 调用它然后删除它,但我想从我的单个 AHK 文件中获取它 运行ning。

尝试以下操作:

Run, powershell.exe -noexit -command ([ADSI]\"WinNT://serverabc123/Administrators`,Group\").Add(\"WinNT://HMM.org.br/Paul1\")

即:

  • 不要使用外引号。

  • \-转义 " 个字符(PowerShell 要求)

  • `-转义 , 个字符(AutoHotkey 要求)