Hey everyone! I'm facing an issue with a computer that has a program set to launch on startup, but it's getting blocked by a pop-up that needs to be cleared by hitting the enter key. I've created a PowerShell script meant to press enter once every minute for 15 minutes to handle this, but it seems like the script isn't working at all—nothing gets sent for the whole duration and then it just exits. I made sure to change the execution policy to 'RemoteSigned' to allow the script to run, but I'm not sure if there's something wrong with the script itself or if I'm dealing with a permissions issue. Here's the script I'm using:
# Create a WScript.Shell COM object for sending keystrokes
$wshell = New-Object -ComObject wscript.shell
# Repeat 15 times (once per minute)
for ($i = 1; $i -le 15; $i++) {
# Send the Enter key
$wshell.SendKeys("~")
# Wait for 60 seconds before next press
Start-Sleep -Seconds 60
}
#Script ends after 15 presses
Any guidance would be greatly appreciated!
2 Answers
Have you considered using AutoHotKey? It might be a more effective solution for handling send keystrokes to a window that’s already displayed. Unfortunately, I understand that installing new software can be a challenge right now.
It seems like sending keystrokes to a new shell might not be the best approach. Are you sure you want them directed at the new script instead of the application already running? It might help to check if the window focus shifts appropriately before sending the keys.
Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically