r/PowerShell • u/GalacticGalaxyyy • Jul 03 '26
Script Sharing Built a global-hotkey "panic button" app entirely in PowerShell (WinForms + RegisterHotKey + taskkill)
Wanted to share a project that pushes PowerShell a bit further than the usual scripting use case — a full windowed app with a tray icon, live hotkey rebinding, and a persistent config, all in one .ps1.
Technical bits that might interest people here:
- Global hotkey via
user32.dllRegisterHotKey/WM_HOTKEY, subclassed on aSystem.Windows.Forms.Form - Foreground window → owning PID via
GetForegroundWindow+GetWindowThreadProcessId, thentaskkill /F /Tto kill the whole process tree - Config persisted to JSON next to the script, hotkey rebindable at runtime by capturing the next
KeyDown - Packaged with a silent
.vbslauncher so there's no console flash and no need to touch execution policy globally
20
Upvotes
5
u/thehuntzman Jul 03 '26
Why taskkill over a native cmdlet like Get-Process piped to Stop-Process? Also vbs is going getting removed from windows soon. I've solved this issue personally with a small compiled c# executable I wrote that launches powershell completely hidden with required arguments coded in for execution policy bypass.
0
u/JSChronicles Jul 03 '26
So alt+f4? I don't think I need a bunch of code to do what 2 keys do on my keyboard
0
u/Koher Jul 03 '26
Looks interesting. Bit asymmetric and blurry(probably cuz dpi) ui but at all works good. I never tried to have a mess with ps WinForms