Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
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". –  surfasb Jan 25 at 1:01
add comment

9 Answers

up vote 138 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

share|improve this answer
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
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
This is not working for me. After I typed my password the command prompt is closed. –  Jonas Dec 9 '10 at 13:44
@Jonas, you might have a renamed Admin account. I had the same issue –  JP Hellemons Oct 11 '11 at 14:23
isn't this asking for the Administrator's password? sudo is asking for your password! –  naxa Sep 18 '12 at 8:42
show 3 more comments

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.

share|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. –  hasenj Nov 19 '09 at 22:28
@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
add comment

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

share|improve this answer
add comment

You can also use the Script Elevation PowerToys.

share|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
@nhinkle can you do elevate command such that it suppresses the popup asking if you want to elevate it? –  barlop Mar 15 at 12:31
show 4 more comments

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 [(-c | -k) [-n] [-u]] [-w] command

  -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".

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.

share|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 '12 at 9:40
@sayap, just to be clear, do you mean this: ss64.com/nt/syntax-uac.html? –  matt wilkie Feb 20 '12 at 18:45
Yes, that's the one. From my limited testing, it works straight away without having to restart Windows. –  sayap Feb 21 '12 at 0:19
there's a similar program with the same name here: wintellect.com/cs/blogs/jrobbins/archive/2007/03/27/… –  Janus Troelsen Feb 6 '13 at 1:21
The only trouble I find with elevate (v1.3.0) is that it does not return the error code from the program it is elevating. –  Ken Aug 14 '13 at 18:41
show 5 more comments

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.

share|improve this answer
add comment

Quick method:

Three steps to add sudo.

1) Open PowerShell.

2) Copy the following script (Ctrl+C) and paste it in PowerShell (Alt+Space+E+P):

$script_path="$HOME\Documents\Scripts"; if (!(test-path $script_path)) {New-Item -ItemType directory $script_path} if (!(test-path $profile)) { new-item -path $profile -itemtype file -force }". $script_path\sudo.ps1" | Out-File $profile -append; "function sudo(){if (`$args.Length -eq 1){start-process `$args[0] -verb `"runAs`"} if (`$args.Length -gt 1){start-process `$args[0] -ArgumentList `$args[1..`$args.Length] -verb `"runAs`"}}" | Out-File $script_path\sudo.ps1; powershell

3) Hit enter.

It will permanently enable sudo command in PowerShell.

  sudo <process-name> [param1 [param2 [param3]]]

  sudo explorer
  sudo notepad
  sudo powershell
  sudo cmd
  sudo taskmgr
  sudo tasklist
  sudo taskkill /IM Skype.exe /PID 8496

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:

Windows Registry Editor Version 5.00
share|improve this answer
I love the powershell solution for this question. This has to be the easiest way to elevate something. Existing .bat files can easily be converted to POSH –  Mitchell Skurnik Feb 14 '13 at 18:05
add comment

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.

share|improve this answer
add comment

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

csudo dism /online /enable-feature /featurename:NetFX3 /All /Source:D:\sources\sxs /LimitAccess

ConEmu will starts dism in the new elevated console/tab (with preceding UAC prompt in Vista or Login box in XP).

By default csudo starts new console in a split (may be changes via editing of csudo.cmd contents).

And of course you may rename it to sudo.cmd if you like "classic" sudo word.

enter image description here

share|improve this answer
csudo.cmd ... dead link –  Joe DF Mar 12 at 5:08
csudo long ago was included in the ConEmu distribution. No link is needed at all. –  Maximus Mar 12 at 8:16
add comment

protected by slhck Aug 29 '12 at 18:25

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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