Introducing UAC Runner for Windows 7

I like to use the keyboard. In fact, I spend as little time as possible using the mouse. It’s not that I’m some kind of ‘133t uber-h4x0r’ that thinks the mouse is just for ‘lusers’, I just guess it’s that for some reason over the years I’ve just found everything much faster and easier with a keyboard. I lose count of the number of times I type [Windows Key]+R, cmd, [Enter] every day.

In addition to this, I have many scripts which I run quite frequently to perform common administrative tasks (backing up a database, configuring IIS to point to the current workspace etc.). However, after the upgrade to Windows 7, I found that many of my scripts would fail, and that I couldn’t perform quite a few actions when I ran stuff from the Run dialog in the normal fashion.

If you’ve read this far, I guess you already know that’s down to UAC, something which means that even if you’re running as an administrator, you still have to run applications that have administrative features with elevated privileges. Not even good old faithful runas can help. Your program will run under an administrative account, but without elevated privileges.

Despite all of this, I’m not here to rant and moan about UAC. In fact, I think it’s a big win security-wise. It’s just that UAC has rather upset my workflow. I like the keyboard. Having to first find the shortcut to the program I want, then right click it, then click ‘Run as administrator’ is, as many people agree, a massive pain in the ass. I don’t disagree with UAC, I just think it could be much much more accessible to keyboard freaks like me.

To ease the burden a little, I put together a small .NET application named UAC Runner. Once sat in your PATH, UAC Runner can be used to easily run programs under UAC from the command prompt or run dialog. Just prefix what you want to run with uac:

Running cmd with UAC Runner

Running cmd with UAC Runner

You’ll then be prompted with the usual UAC dialog. Simply enter some administrator credentials and your administrative command prompt will appear, no mouse required.

UAC Runner can also be used from the command prompt itself, and should work with extra arguments, e.g:

  1. uac sqlcmd -S.\SQLEXPRESS -E

(Yep, that’s right – I occasionally use sqlcmd rather than waiting for SQL Server Management Studio to startup, especially if I just want to run a single line of SQL.)

This is all made possible through a couple of properties on the ProcessStartInfo class, as you may already know. Simply create a new Process object, and set StartInfo.Verb to “runas” and StartInfo.UseShellExecute to true. That’s all there is to it really. Hey, I did mention it was a small application!

  1. using (var proc = new Process())
  2. {
  3.     proc.StartInfo.FileName = fileName;
  4.     proc.StartInfo.Arguments = args;
  5.     proc.StartInfo.Verb = "runas";
  6.     proc.StartInfo.UseShellExecute = true;
  7.     return proc.Start();
  8. }

The benefit to using UAC Runner rather than creating a task, or some other type of agent (e.g. a service which runs constantly with elevated privileges). Is that obviously, you have to specify that you want elevated privileges for every operation. This might seem inconvenient, but it’s much less likely to bite you down the road. Imagine a virus which targeted agents running with elevated priveleges. UAC Runner as a service would be an extremely dangerous thing! The furthest a virus could get with the application at the moment (off the top of my head – feel free to correct me…) would be to try to run something with elevated priveleges leading to an elevation prompt which you could cancel. That’s exactly what UAC was designed for. It can still do its job as effectively as before.

Feel free to download it and try it out. Bare in mind at this stage it’s fairly untested. If you have any issues, please let me know through the issue tracker.

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • email
  • LinkedIn
  • Technorati

Leave a Reply

Your email address will not be published. Required fields are marked *