How to start programs elevated from a batch file

If you use batch files to automate tasks on a computer running Windows 11, 10, 8, or 7, you have probably encountered situations when you needed to start a program elevated (a.k.a. as administrator). For example, if you want to share a folder automatically from a batch file, you would use the net share command. However, unlike many other programs that ask for the administrator’s approval, net share does not do that and simply returns the error code 5 (“access denied”) if it was started by a standard user. How to force that program to start elevated from a batch file?

Encrypt and password-protect files with Encryptability Encrypt and password-protect files with Encryptability encryption software for Windows 11,10,8.

User rating: User rating 4.5/5

Purchase or download a free trial. Read more…

That’s the purpose of the Elevate utility that we’ve created to solve such a problem. Download the Zip file, uncompress it, and inside you should find two files: Elevate.exe and Elevate64.exe. (The latter is a native 64-bit compilation, if you require that, although the regular 32-bit version, Elevate.exe, should work fine with both the 32- and 64-bit versions of Windows).

Copy the file Elevate.exe into a folder where Windows can always find it (such as C:/Windows). To use it in a batch file, just prepend the command you want to execute as administrator with the elevate command, like this:

  elevate net share ...

and it should run the command net share as administrator. Of course, it does not relieve the administrator from the duty to approve the request (unless you have enabled the quiet mode of UAC or disabled the UAC altogether).

The syntax of the Elevate command is as follows:

  elevate [-opt1] [-opt2...] [path\]file[.exe] [param1 [param2...]]

Where -optN can be one of the following:

  -?         - Display the help screen and exit
  -info      - Open the web page with more information (the web page you are reading now!) and exit
  -wait4idle - Wait for the target process to initialize before returning
  -wait4exit - Wait for the target process to finish before returning
  -noui      - Don't display any messages, even if an error occurs

After the options, the following arguments should be entered:

  file       - The file name of the program to launch elevated
  paramN     - Optional parameters (as expected by the program being launched)

For example, if for some reason you want to run Notepad as administrator, and continue only after you exit Notepad, you would use a command like this:
  elevate   -wait4exit   notepad

If you use the elevate command while being logged in to Windows as a user that does not have a split token, that is as a non-administrator or a guest user, it will ask for the administrator’s password to continue. If you use it as the true administrator (that is, if UAC is disabled, or it you’ve launched the batch file itself as administrator), then no administrator’s approval would be required and it would launch the program as usual.

Take control of your files and folders with AB Commander Take control of your files and folders with AB Commander file manager for Windows 11, 10, 8.

User rating: User rating 4.8/5

Purchase or download a free trial. Read more…

Can Elevate.exe be used on a Windows XP or Windows 2000 computer, even though they do not have UAC or users with the split tokens? Yes, it can! In such a case, if the batch file is executed by the administrator, then Elevate.exe runs the program as usual, without requiring any additional approval. If run by a restricted user, Elevate.exe has the same effect as the Run As command of Windows XP/2000: it gives the user an option to enter a different user’s credentials to lunch the program.

The return code of the elevate command depends on the result of its execution and whether you have specified the -wait4exit option or not. If the -wait4exit option is NOT specified, then elevate returns code 0 if it started the target process successfully, or an error code as reported by Windows. For example, if Windows could not find the target file, it usually returns code 2. If the file was found, but the administrator did not approve the request to start the program elevated, the return code is 5. And so on.

However, if you have specified the -wait4exit option on the command line, then if the target process was started successfully, the elevate command would wait for it to finish and return the exit code from that process. The returned value in such a case depends on the program being launched be the elevate command. As with other commands, you can access the return code in a batch file via the ERRORLEVEL variable.

It’s FREE. For Windows 2000 and later. License…


NOTE: There is a known Windows problem: you cannot start a batch file elevated while passing arguments with quotes to it. A possible workaround is not to use elevate.exe to run a batch file elevated. Instead, run the batch file itself as the standard user, and put the elevate.exe command inside of the batch file to run whatever program you need to run elevated.

If you want to link to this article, you can use this HTML code: <a href=””>How to start programs elevated from a batch file</a>

Read more


  1. I was trying this call to build a Visual Studio solution from a batch file in the elevated state
    WCBuild>Elevate -wait4exit “C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\” WinCal.sln /rebuild “Release|x86”

    It did not work. I got an error message ( in the header) stating:
    This program does not have a program associated with it for performing this action.

    I suppose this is because it is the .com extension, which is used for command line builds. Any recommendation?

  2. Could you give example how to run Elevate.exe via .bat file? I had to because I need to execute another file elevated right after install (which stubbornly refuse so) from a .bat that call a series of process. The program i needed to execute by elevate are in the Program File, which I use syntax similiar with the above.

    .bat file ==> call elevate.exe in C: ==> call XX in C:\Program Files

    What is the right syntax?

  3. Adam: please see the examples in the text. Try the one that starts Notepad. You can start another program elevated in the same way. If the program’s file is in the C:\Program Files directory, make sure to include its path into the double quotes.

  4. I am trying to get a desktop shortcut to a UNFiltered.bat file on a flash drive to change dns numbers to run without asking for an administrator password.

    from the command prompt I tried
    elevate -wait4exit C:\Users\unfiltered\Desktop\UNFiltered – Shortcut.lnk
    and it said it worked but it still asked for an administrator password so I tried placing the .bat file on the desktop
    elevate -wait4exit C:\Users\unfiltered\Desktop\UNFiltered.bat
    it still asked for a password, then I tried elevating the file on the flash drive and it still is not working how I want it.
    elevate -wait4exit notepad F:\UNFiltered.bat
    Please help, I do not know what I am doing wrong.

  5. Nathan: this utility does NOT eliminate the need to enter the admin password or approve the elevation prompt. What it does is it tells Windows to run a specific program “as administrator” rather than “as a standard user”. Without this utility, you could launch a program from a batch file only as a standard user. This utility gives you the other option. I hope this clarified the situation.

  6. This works as intended. The sole purpose of this program is to make the program/script run elevated. Credentials still need to be provided though, but this is exactly what I needed. Thank you.

  7. Is there an option to add the credentials to the batch file so that when I launch the batch file I don’t have to type in the administrator credentials every time?

  8. @Grant: There is not option to add the credentials, because Windows does not provide a way to make such an option, sorry.

  9. I’m trying to use this to open an elevated CMD prompt and run a batch file inside that elevated CMD. It opens the elevated CMD fine, but will not run the batch file. Any help??

  10. Karl: this is a known Windows bug. Please see the NOTE above (at the end of the article) for more information.

  11. If executing Elevate from a path with space (e.g. “C:\Program Files\Elevate\Elevate.exe”), it launches with error:

    “Windows cannnot find ‘Files\Elevate\Elevate.exe”‘. Make sure you typed the name correctly, and then try again”

    Is it a bug or I did something wrong?

    Thank you in advance for a great tiny util!

  12. Ngoc Hung: you need to put double quotes around the path with spaces. Also please see NOTE at the end of the article. Good luck!

  13. This is already a big step forward for me. However, I’d appreciate an addition (wish). Maybe when run from a command prompt, there is a chance to elevate the current console instead of opening a new one?
    I did experiment with elevate cmd.exe /K cd, however it seems that opening a new window is built into the program.

    Anyways – thanks for what you’ve already done!

  14. @Eleusius: unfortunately, the elevated instance must be a separate process, it’s impossible to elevate an existing instance, sorry.

  15. Thank you very much for this tool! It helps a lot. One question: I am trying to redirect the output of the program that is run in the elevated shell to a file like this but end up getting an empty file:

    elevate.exe somebatch.bat > output.txt 2>&1

    Do you know how to achieve this or why it does not work?

    Best regards

Leave a comment

Your email address will not be published.

See below before pressing the SUBMIT button!

IMPORTANT! Do not put any URLs in the comment, or it will be rejected. Before submitting, please solve the following simple math problem (so we know that you are not a spambot) :-)

What is nine minus 4 ?
Please enter the answer as a number, 1 through 9:
Please leave these fields as-is: