I always work on a non-administrator account on my Windows computer. Sometimes I need to install programs which requires administrator access. As I mostly use the Windows command prompt, is there a Windows command to escalate privileges, similar to the Linux terminal command sudo?

I believe the term you are looking for is "elevated" access. Even though your credentials have admin permission, processes under your credentials don't have admin permissions until you "sudo" the command. In Windows, they call it "elevate".
–
surfasbJan 25 '14 at 1:01

Just use su and your command. It opens new instance of powershell that is running as admin.
–
IGRACHMar 14 at 17:25

You might find you want the profile loaded (e.g. including environment variables) for any extended use. In which case drop the /noprofile.
–
RichardSep 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,..."
–
lilbyrdieNov 6 '10 at 14:35

4

This is not working for me. After I typed my password the command prompt is closed.
–
JonasDec 9 '10 at 13:44

22

isn't this asking for the Administrator's password? sudo is asking for your password!
–
naxaSep 18 '12 at 8:42

3

Unfortunately, this is seriously outdated. Runas merely runs commands under a different set of credentials. Even though your credentials have admin permissions, it doesn't mean all processes under your credentials run as admin.
–
surfasbJan 25 '14 at 0:59

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.

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.
–
hasenNov 19 '09 at 22:28

2

@hasen j - your issue is just because ~/.themes evaluates before the command is run (and thus before it switches over to root).
–
JaredDec 15 '11 at 18:52

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.

Elevate's purpose isn't to work around or bypass UAC (User Account Control), but to work with it. As long as UAC is enabled there has to be some kind of prompt at some point in the process. If you need to get rid of prompting altogether you have to disable UAC.

The pain point elevate alleviates is escalating a particular process from a non-privileged shell, and then carrying on as normal. Without this you need to start a privileged command prompt with right-click > "Run as Administrator", which can't be easily scripted, before attempting the privileged command.

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

If you are ready to switch to alternative consoles, there is ConEmu (I'm the author). One of its features - the ability to run both elevated and non-elevated tabs in the one ConEmu window. Tabs may be started with different credentials too.

For user comfort, there is batch-file csudo.cmd (which may be easily adopted to bash). Read full description in project's wiki. In brief, when you run some command from existing non-elevated tab, for example

Long method for learning:

Note: I mixed the script from both articles to create the aforementioned script. Rather manually pasting the script in notepad I added the Out-File statements to save ps1 and $profile files from the script.

Tip: If you are not a very big fan of UAC popups (like me), save the following in *.reg file and run it:

surun does a great job. However sometimes under Windows 8 and 8.1 its defaults aren't ideal. Because it replaces Windows's run as function, you are not able to start a command prompt with right click on the start screen.
–
WolfJan 15 at 11:15

As you've probably discovered, runas will let you run as another user but it cannot do elevation and it doesn't pass current directories, environment variables or long command lines.

Hamilton C shell solves that with a genuine su and sudo. su lets you run a command as another user; sudo (actually an alias to su) lets you run a command elevated. You can also do both, running elevated as a different user. Current directories, environment variables and long command lines are passed by way of a shared memory handshake between su running in the caller's context and a copy of itself running as an interlude with the new credentials that then starts the child. Full disclosure: I'm the author.