Run Batch File As Administrator



A new window will appear; under the 'Settings' heading, click the ' Browse ' button and select the executable for the program you wish to launch with administrative privileges from your batch script. In this case, we are using the Thunderbird.exe (executable) located in C: Program Files Mozilla Thunderbird Thunderbird.exe. To elevate batch files manually, you would right-click on it and choose Run as Administrator. Here is a way to automatically elevate a batch file that requires elevated privileges to run correctly. This is equivalent to choosing “Run as Administrator” by right-clicking a batch file. In either case, the UAC prompt would still show up. In order to run as an Administrator, create a shortcut for the batch file. Right click the batch file and click copy Navigate to where you want the shortcut Right click the background of the directory. Now, when I run the batch file, the command prompt is C: windows System32 cmd.exe When I run the dll using shell 32, the executable called is C: windows SysWOW64 cmd.exe.

Administrator

Most of the time, you run Windows batch files using the Command Execution Method, which replicates running them in a command prompt window (cmd.exe). But, what if you need to perform additional processing within the same job and you are running that batch processing in PowerShell? You have several methods to launch Windows batch files from within PowerShell using these methods:

You can start a command procedure from PowerShell with the following code. Replace the path and file with your own information.

Once you’ve called your batch file, you can customize it to the task at hand. For example…

If you want to capture the output of the .bat file, you can use:

If you want to start a process with your .bat file, you can use the PowerShell start-process cmdlet:

And, if you if you want to control cmd.exe, you can use this:

Run

The start-process cmdlet is a standard PowerShell cmdlet, so anyone can use it. JAMS users leverage it regularly and combine it with JAMS specific cmdlets in our PowerShell Scheduler to add intelligent automation to batch files.


In Microsoft Windows, when you try to run a program or perform an operation that requires Administrator privileges, a UAC prompt requires your permission to proceed.

Similarly, you may encounter a permissions error when trying to run commands in a Command Prompt window that require Administrator privileges. These errors happen because UAC blocks the Command Prompt from running Administrator commands unless you run the Command Prompt as Administrator.

UAC acts as a safeguard, requiring your explicit permission to run any software that can modify the Windows system.

Select a link below and follow the steps to run a program as administrator or disable UAC.

Running programs as Administrator

If a program requires Administrator privileges to perform certain functions, you need to run the program as Administrator.

To run a program as Administrator in Windows 10, right-click the icon in your Start menu and select Run as administrator.

For example, in the image below, we are running the Windows 10 command prompt as administrator. We'll discuss this more in the next section.

Run batch file as administrator windows 10

If you right-click a shortcut in your Start menu and the Run as administrator option is not listed, that function is not available for the program.

When you receive the UAC prompt confirming that you want to grant privileges, click Yes.

Running commands as Administrator

In the example above, we ran the Windows 10 command prompt as Administrator. We did this by clicking Start menu > All apps > Windows System, then right-clicking Command Prompt > Run as administrator.

Running the command prompt as Administrator allows you to run commands that change or edit your system files. For example, in the Administrator command prompt, you can successfully run the sfc command (System File Checker).

You should now be able to execute the command you were trying to run previously when you received the error message. With administrative rights activated, the command should execute successfully.

Configuring a shortcut to always run a program as Administrator

To configure most program shortcuts to always run the program as Administrator, follow the steps below.

  1. Locate the program shortcut, right-click the shortcut and select Properties.
Note

If the program icon is in the Start menu, you need to right-click the icon and select Open file location. Then begin with the step above.

Run batch file as administrator from command line
  1. On the Properties window, click the Compatibility tab.
  2. Check the box for Run this program as an administrator and click OK to save the shortcut settings change.

If you do not see a Compatibility tab in the Properties window, follow the steps below instead to always run the program as Administrator.

  1. Repeat step 1 above to access the Properties window for the program shortcut.
  2. On the Properties window, click the Shortcut tab.
  3. Click the Advanced button.
  4. On the Advanced Properties window, check the box for Run as administrator and click OK.
  5. Click OK on the main Properties window to save the shortcut settings change.

Disabling UAC

To disable the User Account Control prompt in Windows, follow the steps below for your version of Windows.

Run Batch File As Administrator Without Uac Prompt

Windows 10 & Windows 8

  1. Open the Windows Control Panel.
  2. Click the User Accounts icon.
  3. Click the Change User Account Control settings link.
  4. Move the slider down to Never notify and click OK.
  5. Click Yes at the User Account Control prompt.

Windows 7 & Windows Vista

C# Run Batch File As Administrator

  1. Open the Windows Control Panel.
  2. Click the User Accounts and Family Safety icon.
  3. Click the User Accounts option.
  4. Click the User Account Control settings link.
  5. Move the slider down to Never notify and click OK.
  6. Click Yes at the User Account Control prompt.

Additional information

  • See the elevated command prompt and UAC definition for further information and related links.