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?
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.
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="https://www.winability.com/elevate/">How to start programs elevated from a batch file</a>
- How to enable or disable test signing mode in Windows
- Email or SMS text messaging are NOT secure for two-factor authentication
- Estimate how much you could save on electric bill with ActiveExit software
- How to delete partition on Windows 11 or Windows 10
- Forget VeraCrypt password? Here is how to recover it.
- Why do my desktop icons keep moving?
- How to create a private folder in Windows 11 and 10
- How to restrict access to Windows Settings with Folder Guard
- Suspending all operations with fascist Russia
- How to keep desktop icons from moving by running Icon Shepherd from command line
- How to restrict access to Task Manager with Folder Guard
- Take ownership of your files after access denied due to NTFS permissions
- How to reprogram or disable CAPS LOCK key
- Encryptability vs Folder Guard: which one to choose?
- Troubleshooting software removal problems using MSI files
- Encryptability: Compare Personal and Business Licenses
- How to add Group Policy and Local Security Policy to Windows 11 and 10 Home edition
- SOLVED – File is too large for the destination file system
- Forget your WI-FI password? Find it in Windows 11 and 10 settings
- What is FAT32 maximum file size limit?
- How to create a secret folder in Windows 11 and 10
- How to easily password-protect Windows Linux folders with Folder Guard
- Force DISKPART to delete EFI system partition in Windows 11 and 10
- How to make Windows 11 and 10 recognize a cloned hard drive again
- How to stop Windows 11 and 10 from using thumbnail preview icons for folders
- How to hide pictures from the Photos app in Windows 11 and 10
- How to save Windows Spotlight photos to your computer
- How to move the OneDrive folder to an encrypted drive
- Windows 10 fails to upgrade? Here is how to fix it.
- How to stop Microsoft Edge from opening PDF files
- Preventing installations of specific programs with Folder Guard
- Folder Guard licensing explained
- Speed up the updates of the network folders
- Make your Windows laptop work as a Wi-Fi access point
- How to stop automatic Windows Update in Windows 10 and 11
- Solved: Windows cannot connect to the printer. Access is denied.
- Migrating encrypted data from TrueCrypt to USBCrypt
- “The Microsoft account service is unavailable right now. Try again later.”
- Using DiffMerge as the external tool of AB Commander to compare plain text files
- How to repair the icon cache and/or thumbnail cache in Windows 11 and 10
- Transferring images between your PC and an Android device: Part 2
- Transferring images between your PC and an Android device: Part 1
- Case study: Using SoftDetective to suppress Corel Guide sign-in prompt
- Using junction points to change the iTunes backup folder location
- How to tell if my Windows computer is 32- or 64-bit?
- How do I stop Windows from rearranging my desktop icons?
- Organize your photo library with the Rename tool of AB Commander
- Windows does not offer the NTFS format option? Here is how to bring it back.
- How to encrypt Firefox profile, bookmarks, and cookies
- Restarting Windows 11, 10, and Windows 8 in the safe mode
- Integrating AB Commander with Universal Viewer
- How to delete a protected EFI system partition with Windows 11,10, 8, or 7
- Using Folder Guard to protect from the social engineering attacks
- How to erase Windows login password if you forget it
- How to unhide a folder hidden with Folder Guard
- How to repair Windows desktop icons with AB Commander
- Slow network in Windows 7 Virtual PC? Speed it up!
- How to show drive letters first in AB Commander and Windows Explorer
- What is my IP address?
- Why can’t I copy large files over 4GB to my USB flash drive or SD card?
- Test the strength of your password with USBCrypt
- How to set up an external text editor for AB Commander
- How to restrict Internet Explorer from downloading programs from the Internet
- Personal vs business license for USBCrypt
- Use Folder Guard to restrict access to Control Panel
- Compare MySecretFolder and Folder Guard
- Hide folders and make files invisible with Folder Guard
- WINEXIT vs ActiveExit: automatically log off users from Windows
- How to protect folder with password in Windows 11 and 10
- How to restrict access and lock external drives with Folder Guard
- How to password-protect Dropbox folder with USBCrypt
- How to set up Folder Guard to stop downloading from the Internet
- Is (Wipe the content) the same as (Secure Delete)?
- How to encrypt and protect the system C: drive with USBCrypt
- Make it easier to return your lost encrypted drive
- USBCrypt for users of Microsoft Office
- How to start programs elevated from a batch file
- How to make elevated programs recognize network drives
- How to disable hibernation
- Using names and labels to organize USBCrypt drives
- How to password-protect a USB flash drive
- Always have a backup of your important files