I always work on a normal account on my Windows box. Sometimes I need to install programs which requires administrator access. As I mostly use a Windows command prompt, is there any command similar to Linux' "sudo"?

link|improve this question

feedback

6 Answers

up vote 70 down vote accepted

The runas command.

runas [{/profile|/noprofile}] [/env] [/netonly] [/smartcard] [/showtrustlevels] [/trustlevel] /user:UserAccountName program

Just run:

runas /noprofile /user:Administrator cmd

to start a command shell as a administrator

link|improve this answer
7  
You might find you want the profile loaded (e.g. including environment variables) for any extended use. In which case drop the /noprofile. – Richard Sep 17 '09 at 9:38
1  
You also have to make sure that the Administrator account has a password. Otherwise you get an error 1327, "user account restriction. Possible reasons are blank passwords not allowed,..." – lilbyrdie Nov 6 '10 at 14:35
2  
This is not working for me. After I typed my password the command prompt is closed. – Jonas Dec 9 '10 at 13:44
The "Account is disabled" checkbox on the user properties must be unchecked for this command to work. – Mike Glenn Dec 14 '10 at 5:05
@Jonas, you might have a renamed Admin account. I had the same issue – JP Hellemons Oct 11 '11 at 14:23
feedback

You can use the runas command which is kind of similar, or you can check out the sudo for Windows project over at SourceForge which adds a sudo command.

The difference is subtle:

Let's say you have two users. Bob is a normal user and James is an administrator.

If you log in as Bob and use "runas james acommand" the command is run as if it was run by James, so it accesses James' user settings and any user changes go into James My Documents & settings folders, etc. So if you are installing an application, say, it will be installed as James, not as Bob.

If on the other hand Bob does "sudo acommand" the command is still run as Bob, but with elevated permissions - just like the Linux sudo command. To prevent any user from being able to sudo you have to define a sudoers user group that contains the list of the normal users that have permission to elevate using sudo. The users still have to provide credentials before elevation.

Sometimes the difference isn't important, sometimes it is, and I find that both commands can be useful.

link|improve this answer
Are you sure? When I run sudo in ubuntu, if my current theme is in ~/.themes then the sudo-ed application will not be able to access that theme, because it's not in /home/root/.themes, and will use the default ugly gtk theme. – hasen j Nov 19 '09 at 22:28
1  
@hasen j - your issue is just because ~/.themes evaluates before the command is run (and thus before it switches over to root). – Jared Dec 15 '11 at 18:52
feedback

You can also use the Script Elevation PowerToys.

link|improve this answer
Awesome - exactly what I was looking for. I didn't want to run as a command has a different user, only to run it with elevated privileges. – orip Mar 14 '10 at 12:55
Exactly the right solution for this problem! Who wants Runas with its messy syntax? – Stabledog Mar 29 '10 at 14:14
I've often wished the elevate command were built into windows. It's a fantastic tool. – nhinkle Nov 11 '10 at 23:43
there's now an Elevation PowerToys collection by the same author from which Creating a Self-Elevating Script is particularly relevant. – matt wilkie Sep 7 '11 at 23:22
feedback

I discovered elevate today which "executes a command with UAC privilege elevation. This is useful for working inside command prompts or with batch files." It's not the same as sudo, it changes the executing user to Administrator, but its syntax is a lot more straightforward to use than runas, and it can keep the current directory, enabling the use of relative paths.

Synopsis:
  elevate [(-c | -k) [-n] [-u]] [-w] command

Options:
  -c  Launches a terminating command processor; equivalent to "cmd /c command".
  -k  Launches a persistent command processor; equivalent to "cmd /k command".
  -n  When using -c or -k, do not pushd the current directory before execution.
  -u  When using -c or -k, use Unicode; equivalent to "cmd /u".
  -w  Waits for termination; equivalent to "start /wait command".
link|improve this answer
This goes perfect with "Elevate without prompting" in secpol.msc. Together, they do the same as %wheel ALL=(ALL) NOPASSWD: ALL in sudo. – sayap Feb 20 at 9:40
@sayap, just to be clear, do you mean this: ss64.com/nt/syntax-uac.html? – matt wilkie Feb 20 at 18:45
Yes, that's the one. From my limited testing, it works straight away without having to restart Windows. – sayap Feb 21 at 0:19
feedback

If you're doing this on Windows, then in addition to the Run As command as mentioned in a couple of other answers, there are also ways to do this with the mouse.

If you hold down the Shift key as you right-click on most executable files in Windows you should notice a few more advanced options. One of these is the "Run As..." option (I think it's called "Run As Administrator" from Vista onwards).

You can also download a more advanced version of RunAs from Microsoft, called ShellRunAs, this has enhancements over the built-in RunAs command, both in command line and graphical modes, including letting you save account credentials

link|improve this answer
feedback

Surun is free, open-source application that allows certain programs to run with administrative rights, without providing a password without changing the user registry or modify environment variables.

When I was using Windows XP this app helps me a lot. Beta works under Windows 7.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.