Elevate a Process at the Command Line in Vista

28 Comments March 27, 2007

Vista is quite nice in keeping you from running too many things at elevated rights so you don't get into trouble. Where things breakdown are when you want to start a particular process with elevated rights from a command line. The RUNAS program does not have any switch to run a program with your user credentials, but let you bump the rights. In addition, if you use RUNAS to start a process that requires elevation, you'll just get an error 740 saying "The requested operation requires elevation." For us old command line jockey's this is not a satisfying situation.

If you want a program to always run with elevated privileges, you can always right click on it in Explorer, select Properties and in the Compatibility tab, tell the operating system you want to always run this program as an administrator.

The only problem is that there are numerous programs you don't want to use the "always elevate" sledgehammer on permanently. For example, I don't run Visual Studio elevated, but there are times when I need to use it elevated. While I could start a separate console with elevated rights, switch to it, and execute the program, that's strikes me as a far too much work when I can write a program instead! Thus Elevate was born. Just execute "elevate notepad" and you'll be prompted with the UAC prompt to run notepad right from the command line.

Elevate will take numerous command line arguments to make your command life a little bit easier and to potentially be used in batch or script files. Here's the help from the program:

Elevate 4.0.10326.0
(c) 2007 - John Robbins - www.wintellect.com

Execute a process on the command line with elevated rights on Vista

Usage: Elevate [-?|-wait|-k] prog [args]
-?    - Shows this help
-wait - Waits until prog terminates
-k    - Starts the the %comspec% environment variable value and
        executes prog in it (CMD.EXE, 4NT.EXE, etc.)
prog  - The program to execute
args  - Optional command line arguments to prog

Note that because the way ShellExecute works, Elevate cannot set the
current directory for prog. Consequently, relative paths as args will
probably not work.

As you can see, Elevate works with %COMSPEC% so my beloved 4NT works as well. Down load the source from here.

The magic that Elevete uses? Passing "runas" as the verb to ShellExecute.


  • Gravatar Image
    links for 2007-03-28 | ITsVISTA March 28, 2007 2:30 AM

    PingBack from http://itsvista.com/2007/03/links-for-2007-03-28/

  • Gravatar Image
    jsantiago September 17, 2007 2:44 AM

    Sound awesome. How about a compiled version for us non-.net folk?

  • Gravatar Image
    Derek Shaw October 26, 2007 3:45 PM

    tantalizing but useless to the sysadmins of the world who don't have time or resources to compile it.

  • Gravatar Image
    jrobbins October 28, 2007 3:15 AM


    Sorry! I fixed the .ZIP to include the .EXE.

    By the way, if you have the .NET Framework installed, you have MSBUILD.EXE and the compilers. In a command window, switch to the source code and execute "MSBUILD foo.sln" to compile the solution.


  • Gravatar Image
    Peter May 6, 2008 8:57 AM

    The Shell execute works exactly as you write in comment, but it's easy to change folder to the absolute path where is required application and then Shell execute and after change it back :-) just my comment ... anyway it's bad that so important functionality is not implemented streight by M$.

  • Gravatar Image
    Rick Saul December 8, 2008 10:32 PM

    Can you advise me please. I am trying to use elevate on winodws 7 beta to do a xcopy

    elevate xcopy c:\source\ C:\destination\

    but all that I get is a shell quickly opening and then closing with no prompts. If I do elevate notepad it opens but no UAC prompts

    regards Rick

  • Gravatar Image
    Alun January 31, 2009 5:16 AM


    Maybe it would work if you launch an elevated command interpreter that then ran xcopy?

    elevate cmd.exe /c xcopy c:\source\ C:\destination\

  • Gravatar Image
    jrobbins January 31, 2009 10:54 AM

    Thanks Alun,

    Yes, if you want to execute command line commands it's best to elevate CMD.EXE or PowerShell.exe and do the command from there.

    - John Robbins

  • Gravatar Image
    Jeremy Quirke February 14, 2009 6:41 AM

    Terrific, exactly what I have been looking for. Cheers mate.

  • Gravatar Image
    kairozamorro July 21, 2009 8:52 PM

    Your elevate tool for command line is quite nice, but for cases where you need to set a working directory or see the ouptut I've got a solution.

    I've got tools for this purpose that you can get from my site (kzorro.webs.com). When you use filedir2prompt in combination with Compatibility Sword, you can easily run a console application/batch file elevated and be able to see the output. I've wrote up a tutorial on creating a shortcut or CSword profile to acomplish this task which you can read up on here:


  • Gravatar Image
    Wayne August 16, 2009 3:32 PM


    I know this is in your archives but I had to write in. What a wonderful tool. I can think of tons of ideas where this can be useful. Thank for you the open source too.

    Hey weird question for you. Sometimes people get weird about modifying and using the software even if it is open source so I wanted to ask first. I was trying to find the licensing for this but couldn't. Since it is open source, is this licensed under the GNU Public license where we can change it, modify it, give it to other people that can use it, etc etc etc without getting into a possible legal battle or is true freeware with no license and it just here do what you want with it software? I know a ton of people that can use this that I can give this to. I just wanted to ask first before I start telling everyone about this.

    This program is a 1000 times better than changing the registry entries every time for a program to elevate here and having to right click. I love the command line. With Vista, it completely took it away if you wanted to utilize UAC other than right clicking and running as administrator. This program has brought it back. :)

    Great job and what an excellent find. I now have your website in my favorites.

    Wayne Leiser, CTO
    Spectacular Computer Repair
    Mon - Thu 11am - 7pm EST
    Fri - Sat 11am - 3pm EST

  • Gravatar Image
    jrobbins August 17, 2009 11:44 AM


    Glad you liked Elevate. As for a license, how about this: I don't really care what you do with it. :) It's so simple there's no need worrying about it. Please feel free to share with as many people as you want. I guess out of courtesy you could refer people to my blog.

    I can't believe this wasn't part of Vista and higher either!

    - John Robbins

  • Gravatar Image
    Wayne August 23, 2009 12:08 PM


    Thanks and I agree with you. I appreciate you putting this together. I am glad I found this. I will post a link to your blog in my forums. Please be advised that I do not get a lot of people to my forums, Mainly just computer repair technicians looking on how to repair something because I psot all of the hard to find repairs online for my own technicians.


  • Gravatar Image
    kairozamorro September 23, 2009 3:35 AM

    Ok don't mean to take attention away from the elevate tool posted here but I'd think it be only fair if I update with my post above.

    FileDir2Prompt as mentioned above in that long tutorial I had up can now elevate and keep output up for display/interaction without having to use a second program.

    How to use in a batch/script file or from command line?

    filedir2prompt /adminapp

    You may also do the same thing using the GUI.

    As for Compatibility Sword I suppose I should have posted an example of what you would put in a batch file/script. You can accomplish the xcopy command shown above in a batch file/script with the following:

    csword /app="c:\windows\system32\xcopy.exe" /param="c:\source c:\destination"

  • Gravatar Image
    BigMac March 4, 2010 3:32 PM

    Is there a way to elevate the rights of the program? I have one program on a 2008 R2 server that runs fine with administrator rights but not as a user. If I have to give all the users an admin name and password to run the program, I might as well set them up as local admins!
    Can't you set up a program just to use elevated rights?

  • Gravatar Image
    jrobbins March 10, 2010 11:43 PM


    Yes you can. Create a manifest file that sits next to the .EXE that sets the autoelevate flag.

    - John Robbins

  • Gravatar Image
    jon hanson May 4, 2010 4:32 PM

    hey im using gygan its a file sharing applacation thats still in beta. how do i elavate it? downloaded the link and now what?

  • Gravatar Image
    John Robbins' Blog June 15, 2010 8:06 PM

    Remote debugging in Visual Studio works great if both machines are on the same domain and/or workgroup.

  • Gravatar Image
    David Meredith June 10, 2011 2:26 PM

    This is great! I combined it with shell registering and unregistering of DLLs from http://forums.webhostautomation.com/showthread.php?t=7851&page=1. So good!

  • Gravatar Image
    Wayne July 17, 2011 3:05 AM

    John, I just found a bug in the elevate program. When utilizing it to send arguments to a secondary batch file, it doesn't handle spaces. It crashes the batch file.

    See: http://forums.techguy.org/dos-other/1007711-solved-sending-variables-crashes-new.html

    When using start to send the variables it works just fine. When utilizing elevate it crashes. After much troubleshooting this was found to be due to the spaces.

    Are you planning on coming out with a version that handles spaces?


  • Gravatar Image
    Wayne July 17, 2011 9:58 AM

    As a matter of fact, currently in windows 7 when utilizing elevate to transfer arguments between batch files such as elevate test.bat
    :: The elevate program cannot handle commas, spaces and \ therefore we need to work around this by changing these to characters that can be handled by elevate.
    :: Change , to $
    :: Change space to _
    :: Change \ to '
    So to work around this we have to change it to characters that Elevate will transfer without causing the new batch window to crash. If this does get repaired with a new version I would love some other options in there such as what the start command has within Windows 7.

  • Gravatar Image
    jrobbins July 17, 2011 11:52 PM


    I looked at your bug report. Elevate is processing the command line options correctly for a program. However, cmd.exe has all sorts of weird command line parsing that I didn't think was necessary in such a simple tool. Elevate comes with source so please feel free to change it to meet your needs.

    - John Robbins

  • Gravatar Image
    max July 20, 2011 10:23 AM

    Excuse me but in the command don't I nust to write the name and password of the administrator?

  • Gravatar Image
    max July 20, 2011 10:26 AM

    Sorry. Can I write all in a batch file dos and run by an icon?

    PS: excuse me for my english, I'm italian.

  • Gravatar Image
    TJ October 14, 2011 1:11 PM

    Look I need to know exactly what to insert into a notepad converted to a batch file to open an elevated cmd prompt. Can Anyone help me with this? If so, please email me at tjmikha@gmail.com. My C:/ drive is unwritable being that it is controlled by a group policy But I know there's a way around this all by having the elevated cmd doing netuser and making my own admin account. I'd like someone to please help.

  • Gravatar Image
    Gominiman December 12, 2011 2:37 AM

    Great little tool. You musy have local admin rights to use this tool effectively....

  • Gravatar Image
    wati boutique April 24, 2013 12:19 AM

    Really do not speak of your ultimate delight to one even less golden as compared with your family. [url=http://e88.fr/]wati boutique[/url] <a href="http://e88.fr/" title="wati boutique">wati boutique</a>

  • Gravatar Image
    Ozzy May 30, 2014 3:54 PM

    Awesome, thanks for these details.

Have a Comment?