3

I have an .exe file that I'm running using Start-Process. Once my application opens, I want to send first tab key and then do alt + tab. I'm using following commands, but so far only my application is launched.

Start-Process -FilePath $Exe -WorkingDirectory $Path 
Start-Sleep 10
[System.Windows.Forms.SendKeys]::SendWait(“{TAB}”)
Start-Sleep 2
[System.Windows.Forms.SendKeys]::SendWait(“%{TAB}”)
Dharman
  • 30,962
  • 25
  • 85
  • 135
Tag
  • 209
  • 1
  • 3
  • 7

1 Answers1

2

Use this:

Start-Process -FilePath $Exe -WorkingDirectory $Path 
$wsh = New-Object -ComObject Wscript.Shell 
$wsh.AppActivate("Window title of $exe")
Start-Sleep 10 
$wsh.SendKeys("{TAB}") 
Start-Sleep 2 
$wsh.Sendkeys("%{TAB}")

You need to activate the exe file's window with its window title. Also prefer Wscript.Shell to send keys. Replace "Window title of $exe" with its window title.

Wasif
  • 14,755
  • 3
  • 14
  • 34