Value returning false when I am trying to mimic keystrokes

Viewed 283

I am trying to write a script and need to mimic some keystrokes after a new dialogue box pops up. When I get to this function block, powershell returns "False" and does not do the 'keystrokes.' I feel like I'm not making it to the next window.

    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 Answers

Powershell is waiting to exit the exe in command. So you need mechanism that run the exe and execute the other commands parallel.

Just change the line :

start-job { cmd /c notepad.exe }

It will start new thread to open notepad and your further code will executed parallel. It sends keys to notepad.

If you want to send tab then you have to use powershell escape character like `t .

Related