Windows 10 bat as administrator

A batch file includes the commands to be executed by Command Prompt in Windows 10 (and older versions). I have already explained what a batch file is and how to create your own. However, you’ll require administrator privileges for your batch file to run some commands in the Windows Command Prompt.

In this article, let’s look at how to enable the ‘Run As Administrator’ option for a batch file in Windows. This simple trick will save your efforts of using the right-click to enable the ‘Run As Administrator’ command prompt every time.

We’ll be using Windows 10 to show the process of automatically running a batch file with Windows admin rights. However, the method works on older versions, including Windows 7 and Windows 8/8.1, as batch files have existed for a long time. Follow the steps mentioned below.

1. Right-click on your batch file.

batch file run as administrator 1

2. Click Create Shortcut

3. Right-click on the shortcut files and click on Properties.

batch file run as administrator 2

4. In the Shortcuts tab, click on Advanced.

run batch file as admin

5. Check the ‘Run as Administrator’ checkbox.

run as admin

6. Click OK to close the dialogue box.

7. Click on Apply to save the changes. Click Ok to close Properties.

Now, every time you run the shortcut file by double-clicking it, the Windows UAC message will be displayed. Click Ok to run as administrator in Windows. This is required as commands would need access to more system-level components that are not available when you open CMD in user mode.

Did you find this helpful? Tell us in the comments below.

Aditya likes to cover topics related to Microsoft, Windows 10, Apple Watch, and interesting gadgets. But when he is not working, you can find him binge-watching random videos on YouTube (after he has wasted an hour on Netflix trying to find a good show).

Reach out at [email protected]

To perform various actions on Windows 10, you can simply use batch files with Command Prompt. While writing commands on your system for DOS or Windows, you need to retype a lot of them in order to run commands. Batch files store the commands in a serial so as to run and executed in the same line-up. The command-line interpreter takes the input from the batch file and executes it in the same order. While there are many ways to run the batch file as Administrator on Windows 10, we discuss them in this article. Let’s begin with an overview of batch files. 

What Is A Batch File?

Batch file is a script file which consists of a series of commands in plain text for executing in the command line interpreter. It was required to make the work easy for users to save the often-used commands. When the batch file is run, the commands are executed line by line. Batch file is in the form of .bat,.cmd,.btm file extensions. You can find it saved in the simple text form on the Notepad or another text editor.

Simple commands for batch files will be:

echo- Prints input string.

cls- Clears command Window.

pause- Stop the batch file execution.

title- Changes the prompt window title.

exit- Exit the command prompt.

copy- Copies a file/files.

::- Add a comment in the batch file.

There are different types of batch files available.

  1. INI – Initialization file is the set of default variables for Windows programs. It is denoted by *.ini
  2. SYS – System files are denoted by *.sys and it may be modified.
  3. COM – Commands files are denoted by *.com and are the executable files for DOS.
  4. CFG – Configuration files are denoted by *cfg.
  5. CMD – Used in Windows New Technology operating systems (32 bit). 

How to create a batch file?

To proceed, all you need is any text editor on your system with knowledge of command prompt. Follow the steps below to create a batch file. In the following method, we make use of a notepad to create a batch file.

Step 1: Open the Start Menu and type Notepad in the search bar. 

Step 2: Open Notepad.

Step 3: Type the following –

@ECHO OFF

ECHO Your first Batch File.

PAUSE.

Create batch file Windows 10

Here we are trying to run a batch file with the result which says –  Your first batch file.

Step 4: Click on File from the menu, and click on Save from the drop-down options.

Step 5: Save the file name with .bat file extension name. For eg: First_batch_file.bat

Run Batch File As Administrator On Windows 10

There are many ways to run batch file as administrator on Windows 10. It can be executed by file explorer, command prompt and task scheduler.

1. Run batch file as administrator on Windows 10 using File explorer-

This is one of the methods to run batch file on demand. Open File Explorer and locate the folder with the saved batch file. To run the batch file as administrator on Windows 10 with the help of file explorer right-click on it. The properties show you the option to Run as Administrator.

Click Yes on the confirmation dialogue box. It is one of the simplest methods to run batch file without command prompt. 

2. Run batch file as administrator on Windows 10 using Command Prompt-

It is another of the method to run batch file as administrator on Windows 10 with command prompt. Follow the steps given below:

Step 1: Open the Start Menu and type command prompt on the search bar.

Step 2: Select Command Prompt and then on the right-side panel click on Run as Administrator.

Step 3: The command prompt opens with the title Administrator: Command Prompt.

Run batch files as administrator on Windows 10 with command prompt

Type the batch file path and name and press Enter.

It is how you can use batch file instead of typing the commands here to execute a task. To run command on command prompt by simply adding a batch file which consists of script.

3. Run batch file as administrator on Windows 10 using Task Scheduler-

Another method to run batch file as administrator on Windows 10 which will schedule a task. The following steps will make you schedule a task by a batch file.

Step 1: Open the Start menu and type Task Scheduler.

Step 2: Open Task Scheduler from the results.

Step 3: To open a new folder, right-click on the Scheduler library. Type a name for your folder and click on OK.

Step 4: On the left panel, right-click on the newly saved folder. Select the Create Basic Task.

Step 5: Give the name and description of the type of scheduled task. Click Next, and select when do you want the task to start off – Daily, weekly, monthly etc.

Step 6: Select the type of the task, and in the Start, a Program section of Action Centre, enter the batch file path from the browser option. And click on Finish.

Wrapping Up: 

This is how you can run batch file as administrator on Windows 10. It included the most commonly used method of using a command prompt to run batch file as administrator. Along with the task scheduler and file explorer which are other methods to run batch file without prompt on Windows 10.

We Love To Hear From You

Please tell us your views on this post in the comments section below. Also, leave your views and queries in the comments section below. We would love to get back to you with a solution. We post regularly on the tips and tricks along with solutions to common issues related to technology. Subscribe to our newsletter to get regular updates on the tech world. Follow us on Facebook, Twitter, LinkedIn, and YouTube and share our articles.

Windows 10 can run special files that contain predetermined sequential commands. In this sense, advanced users can run so-called .bat files, but they must be careful when running them. If you wonder how to run .bat file as administrator cmd in Windows 10? Pay attention to this interesting article.

.bat files are very useful for Windows because they allow the automated execution of a series of tasks that can be very tedious due to their repetitiveness. In these cases, a script with the .bat extension will allow the creation of commands for the development of fast and efficient activities according to the instructions given by the user.

Here is all the information you need to know about .bat files and how to run them from console commands in Windows 10.

cmd motherboard

How do you create a .bat file?

A .bat file must contain several lines of code in order to be executed one after the other (sequentially). To create it, you must right-click on the desktop and select the “New” option. Then, choose “Text Document” and proceed to write the instructions that you want to execute with the file.

Later, save the changes and assign a name to the file adding the .bat extension. In this way, by double-clicking on this file, the system will execute the instructions that you have previously added.

cmd in Windows 10

Run the .bat file as administrator cmd in Windows 10

To run a bath or .bat file as a cmd administrator in Windows 10 you must right-click on the file and, from the context menu, select “Run as administrator”.

You must be very careful when executing a batch file because if you don’t know where it came from, the integrity of Windows files and your own files could be at risk. Some malware and viruses use batch files to damage the operating system and impersonate its essential files. Although, if you are knowledgeable you should have no problems, you can also disable access to the CMD prompt, useful if others use the computer.

On the other hand, if you have general problems with CMD, there are ways to enter the command prompt in Windows 10 when it does not boot. This is not only valid for what was shown before, it will also work at a general level.

Create a shortcut of the .bat file

Create a shortcut to the batch file whose address points to it and, from its “Properties”, choose the “Advanced Options” section to check the “Run as administrator” box. In this way, the Windows command line will execute line by line all the instructions that have been established in your .bat file.

Use the system command line

You can run your .bat file as administrator from another easy way. To achieve this, go to the Windows start menu and in the “Run” option type cmd. Pressing the “Enter” button will open the command console. In it, locate the directory where the .bat file is located and run it by typing its name and extension.

For the above, you can take into account the best lists of CMD commands for networks or for any other function, since these codes will be in charge of performing all the functions when executing a bat.

Download Windows Speedup Tool to fix errors and make PC run faster

You can execute a number of tasks on your Windows computer by running commands. These commands work great. Some people also try to execute a number of these commands one by one. This bulk execution of commands helps them get greater output. But writing and executing these commands one by one manually takes a lot of time.

How to enable 'Run as Administrator' for Batch files on Windows 10

To counter this, Microsoft has added a feature of running Batch files on their operating systems. These batch files are also run by a number of software in the background to execute multiple tasks. But if you are running an independent script, you might need administrator-level privileges to execute them. This is what we are going to talk about in the guide.

If you wish to Run a batch file as an Administrator one time, simply right-click on the batch file that you wish to run and select Run as Administrator.

It will start executing that batch file with administrator rights.

If you wish to automatically elevate a Batch File and make it run as Administrator, follow these steps:

Run Batch file as Administrator

  1. Locate the Batch file
  2. Right-click on the Batch file
  3. Select Create Shortcut
  4. Give it a suitable name
  5. Now right-click the shortcut file
  6. Click Properties.
  7. Select Shortcuts tab > Advanced.
  8. Select Run As Administrator box.
  9. Click OK/Apply and exit.

Now, whenever you run the shortcut, the batch file will always Run as Administrator.

That’s all!

Ayush has been a Windows enthusiast since the day he got his first PC with Windows 98SE. He is an active Windows Insider since Day 1 and has been a Windows Insider MVP.

How do I run a batch file from another batch file with administrator rights?

I have tried the RUNAS command, but it requires the administrator password.

I am searching for an alternative for running a batch file by right clicking on it and running as an administrator. I want to automate it from another batch file.

Peter Mortensen's user avatar

asked Sep 12, 2013 at 4:48

Vinay KV's user avatar

5

Put each line in cmd or all of theme in the batch file:

@echo off

if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)

"Put your command here"

it works fine for me.

MrSmile's user avatar

MrSmile

1,2172 gold badges12 silver badges20 bronze badges

answered Jul 23, 2018 at 5:34

Hossein Jafarinejad's user avatar

1

On Windows 7:

  1. Create a shortcut to that batch file

  2. Right click on that shortcut file and choose Properties

  3. Click the Advanced button to find a checkbox for running as administrator

Check the screenshot below

Screenshot

Peter Mortensen's user avatar

answered Feb 10, 2015 at 14:24

fedmich's user avatar

fedmichfedmich

5,3433 gold badges37 silver badges52 bronze badges

3

You can use PowerShell to run b.bat as administrator from a.bat:

set mydir=%~dp0

Powershell -Command "& { Start-Process \"%mydir%b.bat\" -verb RunAs}"

It will prompt the user with a confirmation dialog. The user chooses YES, and then b.bat will be run as administrator.

Peter Mortensen's user avatar

answered Dec 15, 2014 at 7:40

bismack163's user avatar

bismack163bismack163

2262 silver badges4 bronze badges

0

Use

runas /savecred /profile /user:Administrator whateveryouwanttorun.cmd

It will ask for the password the first time only. It will not ask for password again, unless the password is changed, etc.

answered Sep 12, 2013 at 4:54

user93353's user avatar

user93353user93353

13.7k8 gold badges60 silver badges122 bronze badges

5

If you’re trying to invoke a Windows UAC prompt (the one that puts the whole screen black and asks if you’re granting administrator privileges to the following task), RUNAS is not the smoothest way to do it, since:

  1. You’re not going to get prompted for UAC authorization, even if logged in as the administrator and
  2. RUNAS expects that you have the administrator password, even if your user is setup as a local administrator, in which case the former password is not a sound security practice, specially in work environments.

Instead, try to copy & paste the following code to ensure that your batch file runs with administrator privileges:

@echo off

>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

if '%errorlevel%' NEQ '0' (
    echo Requesting Admin access...
    goto goUAC )
    else goto goADMIN

:goUAC
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:goADMIN
    pushd "%CD%"
    CD /D "%~dp0"

rem --- FROM HERE PASTE YOUR ADMIN-ENABLED BATCH SCRIPT ---
echo Stopping some Microsoft Service...
net stop sqlserveragent
rem --- END OF BATCH ----

This solution works 100% under Windows 7, 8.1 and 10 setups with UAC enabled.

Peter Mortensen's user avatar

answered Oct 31, 2014 at 14:26

alejandrob's user avatar

alejandrobalejandrob

6038 silver badges6 bronze badges

3

Runas.exe won’t work here. You can use VBScript to invoke the «Run as Administrator» shell verb. The Elevation Powertoys contain a batchfile that allows you to invoke an elevated command:

elevatecmd.exe

http://blogs.technet.com/b/elevationpowertoys/

answered Jan 24, 2014 at 6:54

surfasb's user avatar

surfasbsurfasb

9681 gold badge13 silver badges31 bronze badges

1

CMD Itself does not have a function to run files as admin, but powershell does, and that powershell function can be exectuted through CMD with a certain command. Write it in command prompt to run the file you specified as admin.

powershell -command start-process -file yourfilename -verb runas

Hope it helped!

answered Jan 1, 2021 at 4:44

DCT A's user avatar

DCT ADCT A

215 bronze badges

This a trick that i used if anyone wants they can try this in batch file.This will give you the admin prompt when you run the batch file

@echo off
cd \ && cd windows/system32 && command which needs admin credentials
pause

answered Apr 25, 2018 at 11:29

Sushant Baweja's user avatar

Sushant BawejaSushant Baweja

2021 gold badge5 silver badges14 bronze badges

  • Windows 10 android usb modem
  • Windows 10 all versions download
  • Windows 10 airprint activator для windows
  • Windows 10 anniversary edition что это
  • Windows 10 all version activator