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.

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
  • Confirm

Yikes!

Turns out the solution was fairly simple...

(I'm using Windows 7 btw)

  1. Create a shortcut to the script you want to run
  2. Right click the shortcut and hit Properties
  3. On the Shortcut tab click the Advanced button
  4. Check the 'Run as Administrator' option (if this is grayed out curse Microsoft and hit Google for some solutions)
  5. Click OK
  6. 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!

Published on Tuesday, June 25 2013    

COMMENT / SHARE

Comments disabled for this post. Still want to bug me about it? Hit me up on one of the social sites listed to the right.

About

Jim is a Senior Applications Engineer working at Red Hat. He slso likes motorcycles and keeping his quadcopter out of trees.