closing application window on powershell

Hello All,

I have this bit of code that opens a self made application and presses return.
I want to then close the application but I cannot get it to close. This is my code. Anyone help? Thanks.

[pre]

C:\Users\App.exe
$wshell = New-Object -ComObject wscript.shell;

Sleep 3
$wshell.SendKeys(’~’)

$wshell.closemainwindow

[/pre]

I would change line 1 to:

$proc = Start-Process -FilePath "C:\Users\App.exe" -PassThru

Then when you are done with your SendKeys you can:

$proc.Kill()

 

yes. perfect. Thanks very much :slight_smile: