AutoHotkey and Run As AdministratorTuesday, June 25 2013
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:
My restart script for example will shutdown my SQL and web server (in this case MSSQL and IIS) and Railo and restart them all.
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.
;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
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
;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!