AutoHotkey and Run As Administrator
For as long as I’ve been developing ColdFusion (and now Railo) I’ve always had a few batch files to start/stop and restart my web services:
- railo_restart.cmd
- railo_start.cmd
- railo_stop.cmd
My restart script for example will shutdown my SQL and web server (in this case MSSQL and IIS) and Railo and restart them all.
:::bat
net stop "W3SVC"
net stop "MSSQLSERVER"
net stop "RAILO"
net start "W3SVC"
net start "MSSQLSERVER"
net start "RAILO"
I have a simple AutoHotkey script that will run this with a single keypress:
Note: I’m using a Microsoft Natural keyboard with several additional function keys and have this mapped to the ‘=’ key on the number pad.
:::ahk
;numpad=
run "C:\scripts\batch\railo_restart.cmd"
return
Unfortunately my laptop is locked down and I need to “Run as administrator” which requires me to
- Open my file manager
- Right click on the file
- Find the “Run as adminstrator” button
- Click it
- Confirm
Yikes!
Turns out the solution was fairly simple…
(I’m using Windows 7 btw)
- Create a shortcut to the script you want to run
- Right click the shortcut and hit Properties
- On the Shortcut tab click the Advanced button
- Check the ‘Run as Administrator’ option (if this is grayed out curse Microsoft and hit Google for some solutions)
- Click OK
- Turn off UAC (this is a security risk!). This eliminates the confirmation.
Now tweak the AutoHotkey script to point to the shortcut instead
:::ahk
;numpad=
run "C:\scripts\batch\railo_restart - Shortcut.lnk"
return
Now when I click the ‘=’ key on my keyboard the script fires off with no prompts or confirmations, running as adminstrator!