Tuesday, September 9, 2008

Announcing Sudo for Windows

If you’ve used a Unix much, I’m sure you’re familiar with sudo, a command-line utility that lets you run things as the superuser. Not only it is very handy, but it is the basis for one of the better XKCD strips.

Sudo is one of those things I find myself wishing for in Windows, especially given the new(ish) UAC features in Vista/Windows 2008. There are lots of times when I just want to run something as administrator, dammit. Typing “sudo notepad2 C:\somewhere\foo.txt” would fit the bill.

I tried Sudo for Windows, but it made me type my password. That seemed silly, given that I don’t need to type my password anywhere else to run things elevated. There are probably other implementations of this out there, but it literally took less time to write my own than it would to crawl through all of them looking for the one I like best. All it does is execute whatever arguments get passed to it, but the program itself has the “require administrator” bit in the manifest, so the target program winds up running elevated as well.

Anyway, it’s in my arsenal. Visit here to get it in yours, too.


  1. I don't know how your version of sudo works but if it just starts an application with the administrator bit set then it still has the UAC popup so this is good.

    The only difference with linux is that when you have used sudo in the shell and authenticated then successive usage of the command prevents entering the password everytime which is not the behaviour of your tool and cannot be done either because of the way the Vista commandshell works.

    The only workaround is: sudo cmd.exe and that is what I have running here. I have a shortcut that just launches a commandprompt with the run as administrator flag set.

    But still a nice addition to my commandline tools.

  2. Here's my sudo batch file solution:

    runas /env /savecred /user:localhost\Administrator "%*"

    Use /savecred so you don't have to type password every time(only the first time). Don't forget to specify "localhost" otherwise it runs much slower.

    Put the batch file into both system folder(or somewhere in your path) and start menu folder, so typing "sudo xxx" works both on the run dialog an the start menu search box.

  3. Nice - I like it. But it's slightly different from my sudo, as your solution actually causes the target process to run as the "Administrator" user, not as me. That can occasionally cause problems.

  4. You're right. Hopefully /env could take care of some of those cases.

  5. Is this file still available? The links listed on the page linked above show file not found.

  6. There's some maintenance work going on right now. Should be back up in an hour or two.

  7. Should be fixed now.