2

I have a PowerShell script that runs a program which requires a user to press "Enter" before the script can advance. Being that I'm trying to automate this process, I want to eliminate user involvement. Is there a way to simulate this "Enter" press within the PowerShell script? I have tried:

$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('title of the application window')
Sleep 1
$wshell.SendKeys('~') 

and

$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('title of the application window')
Sleep 1
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait('~');

but it still requires the user to press "Enter" and then it prints "False". It then adds a return at the very end of the program regardless of this code placement in the program.

CS student
  • 305
  • 1
  • 3
  • 13

1 Answers1

4

I used this code at the beginning of my function:

$myshell = New-Object -com "Wscript.Shell"
$myshell.sendkeys("{ENTER}")
CS student
  • 305
  • 1
  • 3
  • 13