当我尝试模拟击键时,值返回false

时间:2019-06-21 03:29:42

标签: powershell

我正在尝试编写脚本,并且需要在弹出新对话框后模仿一些按键操作。当我转到该功能块时,powershell返回“ False”,并且不执行“击键”。我觉得我没有到达下一个窗口。

    function ats{
      $wshell = New-Object -ComObject wscript.shell;
      cmd /c C:\location\location\ats.exe
      $wshell.AppActivate('Administrative Tool Suite (ATS)')
      Sleep 1
      $wshell.SendKeys('TAB')
      sleep .5
      $wshell.SendKeys('TAB')
      sleep .5
      $wshell.SendKeys('TAB')
      sleep .5
      $wshell.SendKeys('TAB')
      sleep .5
      $wshell.SendKeys('~')
    }
    ats

1 个答案:

答案 0 :(得分:0)

Powershell正在等待退出命令中的exe。因此,您需要运行exe并并行执行其他命令的机制。

只需更改行:

start-job { cmd /c notepad.exe }

它将启动新线程以打开记事本,并且您的其他代码将并行执行。它将密钥发送到记事本。

如果要发送tab,则必须使用`t 之类的Powershell转义字符。

相关问题