Elevate a Process at the Command Line in Vista

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 – training.atmosera.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.

John Robbins

View Comments

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

  • All,
    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.
    -John.

  • 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$.

  • 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

  • Rick,
    Maybe it would work if you launch an elevated command interpreter that then ran xcopy?
    ie.
    elevate cmd.exe /c xcopy c:source C:destination

  • 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

Recent Posts

How to Navigate Azure Governance

 Cloud management is difficult to do manually, especially if you work with multiple cloud…

5 days ago

Why Azure’s Scalability is Your Key to Business Growth & Efficiency

Azure’s scalable infrastructure is often cited as one of the primary reasons why it's the…

3 weeks ago

Unlocking the Power of AI in your Software Development Life Cycle (SDLC)

https://www.youtube.com/watch?v=wDzCN0d8SeA Watch our "Unlocking the Power of AI in your Software Development Life Cycle (SDLC)"…

1 month ago

The Role of FinOps in Accelerating Business Innovation

FinOps is a strategic approach to managing cloud costs. It combines financial management best practices…

1 month ago

Azure Kubernetes Security Best Practices

Using Kubernetes with Azure combines the power of Kubernetes container orchestration and the cloud capabilities…

2 months ago

Mastering Compliance: The Definitive Guide to Managed Compliance Services

In the intricate landscape of modern business, compliance is both a cornerstone of operational integrity…

2 months ago