You may need to run a batch file to configure devices, delete or copy files, or perform other tasks each time the computer loads to help it run more efficiently or allow a device to run. Below are steps on how to make any batch file run each time you boot into Windows.
If there are two or more user accounts on the computer, the batch file runs after the user logs in to Windows.
Run a batch file at loading of Windows 8 and 10
- Create a shortcut to the batch file.
- Once the shortcut is created, right-click the shortcut file and select Cut.
- Press Start, type Run, and press Enter .
- In the Run window, type shell:startup to open the Startup folder.
- Once the Startup folder is opened, click the Home tab at the top of the folder. Then, select Paste to paste the shortcut file into the Startup folder.
Run a batch file at loading of Windows 98, XP, NT, 2000, Vista, and 7
- Create a shortcut to the batch file.
- Once the shortcut is created, right-click the shortcut file and select Cut.
- Click Start, then Programs or All Programs. Find the Startup folder and right-click that folder, then select Open.
- Once the Startup folder is opened, click Edit in the menu bar, then Paste to paste the shortcut file into the Startup folder. If you do not see the menu bar, press the Alt to make the menu bar visible.
Any shortcuts in the Startup folder automatically run each time the user logs in to Windows.
I n this tutorial, we are going to see how to run a batch file in CMD. CMD is one of the oldest software components of Windows. The command prompt has offered the possibility to make direct changes to Microsoft operating systems for several decades. Batch files (or Bat files) are closely related to the command prompt. They provide access to the internal commands of cmd.exe and allow batch processing of commands. Find out here what makes these scripts so useful and how to run a batch file in CMD.
How to Run Batch File in CMD
Suppose you have already a batch file.
How to Create a Batch File in Windows In this tutorial, we are going to see how to create a batch file in Windows. Creating your own Bat files is useful when you… Read More
If you want to open the batch file from the command line, proceed as follows:
Step 1: Open the Windows search function and type CMD. Then click on Command Prompt to start the command line normally. Select it with a right-click and click Run as administrator, if it requires administrator rights.
Step 2: Use the “change directory” (cd) command to access the directory where the batch file is located. Then type the name of the batch script (including the file extension) and press Enter. Here in this example we have the file called ‘app.bat’.
As you can see we have run the batch file and it display “Hello World” on the screen.
Batch File Commands List With Examples In this tutorial, we are going to see a list of batch file commands with examples. Batch files are batch files that allow Windows users… Read More
- How to Run EXE File in CMD
cmd.exe, also known as a Command Prompt, is one of oldest software components in Windows. For decades, this command-line processor has been used to make direct changes to Microsoft operating systems. Batch files (also known as .bat files) are closely associated with Command Prompt. These files contain native commands that cmd.exe uses to process a sequence of commands. We’ll explain the unique features of these useful scripts and show you how to create, save, and run batch files yourself.
Register great TLDs for less than $1 for the first year.
Why wait? Grab your favorite domain name today!
What is a batch or .bat file?
A batch file (also known as a .bat file or batch script) is a text file that the Windows cmd.exe command line processor executes as a batch job. Command Prompt assumes both the role of interpreter and runtime environment. Put simply, a batch file is a computer program or script containing data or tasks that are processed sequentially by Command Prompt.
The term “batch processing” comes from the early days of data processing, when interactive processing was not yet possible. Back then, data sets were usually stored on punched cards that were processed one card at a time in batches. In modern computer operating systems, the term came into widespread use with MS-DOS (1981) and refers to the batch files we’re discussing in this tutorial.
Batch files allow you to use and run ordinary CMD commands with cmd.exe as the interpreter and runtime environment. You can also use comments, labels, variables, conditions, and queries when writing a batch file. To convert text files to batch files, you have to use the .bat extension in newer Microsoft systems. The .cmd extension was common in Windows NT and OS/2.
In 2006, Microsoft released PowerShell, another framework that allows you to program and execute batch files. It was made open-source and cross-platform in 2016 and uses the MIT license. PowerShell provides an alternative command line interpreter and its own scripting language called PowerShell Scripting Language.
Creating a batch file: Step-by-step tutorial
Creating your own batch files is useful for automating the execution of recurring command sequences. These sequences might include login processes or what is known as TSR programs (Terminate and Stay Resident) that you want to run continuously as background processes. In the following sections, we’ll explain the tools you need to create batch files and show you how to create, save, and run your own batch files.
Step 1: Select and open your editor
As mentioned earlier, text documents are a good starting point for batch scripts. To write your own batch file, all you need is an ordinary text editor. You don’t really need features like syntax highlighting, so the Notepad application included with Windows is perfect. To open it, simply type “Notepad” in the Windows search bar and click on the Notepad icon in the search results:
A batch file is a file that contains MS-DOS commands and when the batch files are clicked or called these commands are executed. Batch files also called BAT files. Most of the operating systems like windows provide the ability to create and run batch files. In this tutorial, we will learn how to create a batch file for MS-DOS and PowerShell, How To Run, or Execute Batch File?
Batch files are supported by all modern Windows operating system versions like Windows XP, Windows 7, Windows 8, Windows 10 and Windows Server versions. But the batch files contents like commands, binaries and features should be compatible with the current operating system in order to execute in reliable way. If specific command, binary or feature is not supported it will be skipped and not executed but others lines of batch file will be executed.
What Is Batch File?
Before starting to create and running batch files we should learn what is a batch file. A batch file is a simple text file that has the *.bat file extension and contains MS-DOS commands or binary files. Batch files also balled as BAT files because of their extension. Batch files are popular among system administrators and technical people in order to complete repetitive or non-interactive jobs easily and reliably. Even interactive jobs can be completed with batch files with little or no effort or action.
Advantages of Batch/BAT Files
Batch or BAT files are a lot of advantages for Windows users. Below we will list some of them.
- Offload repetitive tasks and automate them.
- Reliable command execution
- Noninteractive command execution.
- Advanced reporting and performance tracking
- Scheduled tasks can be executed on different dates and times.
Create Batch File
Batch files are a simple text file which contains MS-DOS and related commands and binaries. First, open Notepad and create a file and save the file whatever name you want but set the file extension as *.bat .In this example we will create the batch file named runwise.bat . Batch files may also use extensions like .cmd and .btm.
Save Batch File
The saved batch file will look like below. As you can see the batch files or files with *.bat extension has the following file icon which simply used for system-related files. By default, the .bat extension is not displayed.
Batch File on Desktop
Run Batch File
In order to run batch files content and commands batch files should be executed properly. Batch files can be executed in the following ways.
- Clicking on Batch File
- Using Scheduled Jobs
- Calling From MS-DOS or PowerShell Command Lines
- Calling Another Batch File
Run Batch File By Clicking
The simplest and most popular method to run a batch file is just clicking on the batch file. This is a GUI method to run a batch file where it can be used from desktop or file explorer. Double-clicking on a batch file will run the batch file in an MS-DOS command prompt.
Run Batch File By Clicking
Run Batch File Using Scheduled Jobs
Scheduled Tasks is a tool used to schedule different jobs or tasks to run the future at the specified date or time or repetitively etc. It is recently called as Task Scheduler and can be opened by typing schedule in the start menu like below.
Open Task Schedular
In the following screen you can create a new task for the batch file. We will click to the Create Basic Task in order to create a new task.
Create New Task
In the following screen we will set the name of the task which is not the batch file name. Then we will click to the Next .
Set Task Name
In the following screen the date or time of the execution will be specified. The batch file will be executed at the specified date, time or interval.
Set Period of Task
As we have selected daily the start date with the time and recur count will be provided in the following screen.
Set Time For Task
This step is important where we will select the Start a program in order to specify our batch file to execute.
Set Task Action
This step is the most important to schedule our batch file. In the program script part, we will specify the script file location. Also, the Browser button can be used to select and specify a batch file location. Also, we can specify arguments to be passed into the batch script from the Add arguments textbox.
Specify The Batch File Path
Following screen is the last screen where we all information about scheduled batch job will be displayed.
Review Scheduled Batch File Configuration
Run Batch File From MS-DOS or PowerShell Command Lines
Batch files can be run from MS-DOS or PowerShell command lines. MS-DOS command line can only run MS-DOS based batch files and con not run PowerShell batch files. But PowerShell command line can run both MS-DOS and PowerShell batch files. In order to run a batch file from the MS-DOS command line just specify the batch file name with the full path. Alternatively, if the batch file is located in the current working directory only the name of the batch file can be called.
Run Batch File As Command
Or alternatively the complete path of the batch file runwise.bat can be provided from any directory like below.
Specify Batch File Complete Path
Run Batch File From Another Batch File
Batch files can call another batch file like a regular MS-DOS command. The most important thing about running a batch file in a batch file is to provide the complete path of the batch file. Even just the name or relative path can be used to run a batch file in a batch file the most reliable way is using the absolute or complete path of the batch file.
Run Batch File As Administrator
If the batch file has commands that need to be executed as Administrator or with Administrative privileges you should open the MS-DOS or PowerShell as Administrator. Please follow the following tutorial in order to open MS-DOS, Command Prompt, or PowerShell as administrator and then use previously described steps like “Run Batch File From MS-DOS or PowerShell command line“.
There are occasions where you might need to schedule to run a batch file automatically in your Windows. In this article, I’ll share a tip on how to schedule a Batch file automatically using Task Scheduler.
Schedule a Batch File to run automatically
- Create a Batch file
- Open Task Scheduler
- Create a Basic Task
- Open Task Scheduler Library
- Make Task runs with the highest privileges.
Step 1: Create a batch file you wish to run and place it under a folder where you have enough permissions, for example, under C drive.
Step 2: Click on Start and under search, type in Task, and click open Task Scheduler.
Step 3: Select Create Basic Task from the Action pane on the right of the window.
Step 4: Under Create Basic Task, type in the name you like and click Next.
Step 5: From the Trigger, select the option you like and click Next.
I chose Daily and clicked Next, which brought me to this screen.
Step 6: Then click on Start a Program and click Next.
Step 7: Now click on Browser and select the batch file you would like to run.
Step 8: Finally, click on Finish to create the Task.
Now that we have created a Task, we must make sure it runs with the highest privilege. Since we have UAC settings, we have to make sure that it should not fail if it does not bypass the UAC settings when you run the file.
So click on Task Scheduler Library.
Then double click on the Task you just created.
Step 8: Click on Run with Highest privilege, then click OK.
You have successfully created a Scheduled Task to automate a batch file. However, there can be drawbacks such as if the application you are trying to invoke needs a password. In that case, you cannot run it silently.
How do I run multiple batch files after one?
If you want to run batch files one after another, you can use the task scheduler and time them to run with the one-minute gap. The other way is to create a mother batch file, add a list of all bat files inside it, and let it execute one after the other.
How to add timeout or sleep in a Batch File?
You can add the following command along with other parameters. It will make sure user input is not considered, and there is no output for this.
How to run the batch files on Startup?
When setting up the task with the scheduler, you can run it as soon as you log into the PC. It can be delayed by a minute, but it will be executed. If you need to run it every few minutes, make sure to set it accordingly.
Could you please help me to execute a bat file silently as an administrator. Is it possible to add run as administrator option in a bat file. I tried the below command, but its not worked for me.
msiexec.exe /i “F:\Test\DesktopCentral_Agent.msi” /quiet /norestart
I am getting this error below.
The installer has insufficient privileges to access this directory: C:\Program Files (x86)\DesktopCentral_Agent. The installation cannot continue. Log on as administrator or contact your system administrator.
- Sort by Created Created
- Sort by Oldest Oldest
- Sort by Votes Votes
Based on the question, I am assuming that the user who is running the bat file is a standard user and not an administrator and does not know the administrator password. Is that a correct assumption?
If so, is this what you are looking for?
There is no magic switch to allow a standard user to gain administrator access without somehow providing administrator credentials. That would be a security hole. Of course if you save the credentials of the administrator account as that page describes, that may also be a security hole.
There may be other alternatives (task scheduler) that you could use, but you would need to explain more about what you are trying to accomplish.
User has admin rights and able to execute the command. But its need to run as admin to execute the command properly, otherwise it wont work and shows the error mentioned below
“The installer has insufficient privileges to access this directory: C:\Program Files (x86)\DesktopCentral_Agent. The installation cannot continue. Log on as administrator or contact your system administrator.”
Refer to the link below:
Note: This is a third-party link and we do not have any guarantees on this website. And Microsoft does not make any guarantees about the content.
Try this bat file. If the user right clicks the bat file and selects “Run as Administrator”, it will detect that it is elevated and will call the installer. If it is not elevated it will use powershell to invoke the UAC prompt and run the installer.
Just to check if the above reply could be of help, if yes, you may mark useful reply as answer, if not, welcome to feedback.
Kick off your batch file when your PC boots. Automatically restart it when it stops.
AlwaysUp version 13 (released in October 2021) introduced a very easy way to make your batch file start at boot and run 24/7.
The new Application Advisor will help you install your batch file as a Windows Service with all our recommended settings — in just a few clicks. Simply select Advisor from the Application menu and follow the straightforward prompts.
To set up a batch file to run as a Windows Service with AlwaysUp:
Download and install AlwaysUp, if necessary.
Select Application > Add to open the Add Application window:
On the General tab:
In the Application field, enter the full path to the batch file. We have chosen our sample batch file, C:\BatchFile\RunNotepad.bat, which contains the following instructions (to launch the Notepad application):
In the Name field, enter the name that you will call the batch file application in AlwaysUp. We have used My Batch File but you can specify virtually anything you like.
If your batch file calls a program that needs access to its registry settings, etc., then you will want to click over to the Logon tab and enter the user name and password of the account that can run the software normally.
Click the Save button. In a couple of seconds, an application called My Batch File will show up in the AlwaysUp window. It is not yet running though.
To start the batch file, choose Application > Start “My Batch File”.
The batch file is currently running in Session 0. On Windows XP and Server 2003, we can see it by logging on to that session. On Windows 8/7/Vista and Server 2012/2008, we can see it if we go to the isolated Session 0 by selecting Tools > Switch to Session 0:
That’s it! Next time your computer boots, the batch file will be launched immediately, before anyone logs on. We encourage you to explore the many other settings that may be appropriate for your environment.
It is also possible to run batch scripts with the .BAT extension, but this is not recommended unless you need compatibility with Windows 95 (.BAT files will set ERRORLEVEL following inconsistent MS-DOS style rules).
Run a batch file
A batch file can be run by double clicking it in Windows explorer, or by typing the name/path at the command line, optionally passing any parameters needed.
From the start menu: START > RUN c:\path_to_scripts\my_script.cmd , OK
If the filename includes any spaces, then you will need to surround the command with quotes:
"c:\path to scripts\my script.cmd "
Open a new CMD prompt by choosing START > RUN cmd , OK
From the command line, enter the name of the script and press return.
C:\Batch> c:\path_to_scripts\my_script.cmd param1 param2
This can be made easier by creating a shortcut for the start menu or taskbar.
To run a batch file from within another batch file, use the CALL command, otherwise the first script will start the second script and immediately exit, so any further commands in the first script will not run.
View the startup command line
The environment Variable %CmdCmdLine% will expand into the original command line passed to CMD.EXE
When a batch file is launched from the command line %CmdCmdLine% will return:
When a batch file is launched by double clicking in Windows Explorer or START > RUN, %CMDCMDLINE% will return:
C:\WINDOWS\system32\cmd.exe /c ""C:\demo\batch.cmd param1
The /c can be used to detect the start mode:
Echo %CmdCmdLine% | findstr /c:" /c " >nul && Echo Started with a double click.
Run a PowerShell script
To run a PowerShell script from the CMD shell:
If the arguments need quotes you will need to triple them so they are escaped:
When calling PowerShell from CMD be aware that a comma is a CMD delimiter, this makes it impossible to pass an array of comma separated values to PowerShell. item1,item2,item3 is treated the same as item1 item2 item3
Run a VBScript file
To run a VBScript from the CMD shell:
“The method of the enterprising is to plan with audacity and execute with vigor”
Batch files are used widely by computer handyman to simplify everyday tasks, to shorten the time and save unnecessary hassle. So what is a batch file? Can you create a batch file yourself? How to run the bat file on computer? These questions will be answered below.
You’d better turn to MiniTool Solution when you want to secure data or recover lost files from PC.
How to Create a Batch File Windows 10
What is batch file?
Batch file (also known as bat file) is actually a special kind of text file with a .bat extension. You can put some commands into the batch file to turn a complex process into a simple task. In this way, the commands can be run in sequence as soon as you click on the file. In short, the bat file is a script file in DOS, OS/2 and Microsoft Windows.
People are wondering how to create a batch file easily. Therefore, this part will focus on how to make a batch file in 2 ways.
How to Create a .bat File in Microsoft Windows 10
Firstly, you need to make sure you have a text editor (Notepad or WordPad is ok) and some basic using knowledge of Command Prompt. Then, follow the steps below.
How to make a bat file (simple bat file):
Step 1. Right click on the blank area on your PC screen.
Step 2. Choose New from the menu.
Step 3. Select Text Document from the submenu.
Step 4. Double click on the New Text Document file on desktop to open Notepad window.
Step 5. Type the following content into it:
ECHO Congratulations! Your first batch file executed successfully.
Step 6. Select File from menu bar.
Step 7. Select the Save As… option.
Step 8. Type a name into the textbox after File name (add .bat extension to it) and choose a location to save the simple batch file.
Step 9. Click on the Save button to confirm.
There’s another way to open the Notepad window:
- Click on the Cortana search icon/box on taskbar.
- Type notepad and select Notepad from the result.
If you want to create an advanced Windows batch file or actionable batch file, you should also open the Notepad window -> type the corresponding content -> save it as a bat file.
How to Create a Bat File in MS-DOS
This way only works on the computers running a 32-bit version of Windows. If your system is 64 bit, please use the above steps.
Step 1. Open Windows search box and type cmd.
Step 2. Select Command Prompt from the result to open MS-DOS prompt.
Step 3. Type edit test.bat and hit Enter.
Step 4. A blue edit screen will appear. Type the following content into it:
echo Hello this a test batch file
Step 5. Find and click File.
Step 6. Choose exit from the menu.
Step 7. Click on the Yes button to save it.
If you want to execute the test.bat file, just go back to the MS-DOS prompt -> type test -> hit Enter.
That’s all about how to create.bat files.
How to Run a Batch File
Run in file explorer:
- Open File Explorer on your Windows 10.
- Navigate to the drive and folder that include the Windows batch file.
- Just double click on the batch file to run it.
Run a batch file from Command Prompt:
- Open Windows search and type cmd.
- Right click on Command Prompt and choose Run as administrator.
- Type C:\Users\folder location\filename.bat and hit Enter.
In addition, you can run a bat file in Windows 10 on scheduled through Task Scheduler or run the batch file on startup via file explorer.
ABOUT THE AUTHOR
Sarah has been working as an editor at MiniTool since she graduated from university. Sarah aims at helping users with their computer problems such as disk errors and data loss. She feels a sense of accomplishment to see that users get their issues fixed relying on her articles. Besides, she likes to make friends and listen to music after work.
This article explains what a BAT file is, how to open one for execution, how to edit one to make changes to it, and how to convert a BAT file to EXE, MSI, or another format.
What Is a BAT File?
A file with the .BAT file extension is a Windows Batch file. It’s a plain text file that contains various commands used for repetitive tasks or to run groups of scripts one after another.
Software of all types use BAT files for various purposes—for example, to copy or delete files, run applications, and shut down processes.
They're also called batch files, scripts, batch programs, command files, and shell scripts, and may instead use the .CMD extension.
Working with BAT files can be very dangerous to not only your personal files but also important system files. Take extreme caution before opening one.
How to Open a .BAT File
Even though the BAT extension immediately makes Windows recognize such a file as executable, they are still composed entirely of text commands. This means any text editor, such as Notepad, including in all versions of Windows, can open one for editing.
To open the BAT file in Notepad, right-click it and choose Show more options > Edit from the menu (or just Edit in some Windows versions). You might find it helpful to use more advanced text editors that support syntax highlighting when editing a BAT file.
Opening it in a text editor will display the code that makes up the file. For example, this is the text inside one used to empty the clipboard:
Here’s another example of a BAT file that uses the ping command to see if the computer can reach a router with this particular IP address:
Again, as an executable file extension, take great care when opening BAT files you have received via email, downloaded from websites you’re not familiar with, or even created yourself.
How to Use a BAT File
Using a BAT file in Windows is as simple as double-clicking or double-tapping it. You don't need to download any special program or tool.
To use the first example from above, entering that text into a text file with a text editor and then saving the file with the .BAT extension will make it an executable that you can open to immediately erase anything saved to the clipboard.
The second example will ping that IP address; the pause command keeps the Command Prompt window open when the process is finished so you can see the results.
If your file doesn’t seem to be a text file, then you’re probably not dealing with a BAT file. Check the file extension to make sure you aren’t mixing it up with a BAK or BAR (Age of Empires 3 data) file.
How to Convert a .BAT File
As shown, the code of a BAT file is not hidden in any way, which means it’s very easy to edit. Because certain instructions in one (such as the del command) can wreak havoc on your data, converting the BAT file to a format like EXE to make it more like an application file might be wise.
You can convert BAT to EXE using a few command line tools. See How-To Geek for directions on how to do that.
- Windows’ built-in IExpress tool provides another way to build an EXE file from a BAT file. Open it from the Run box with iexpress.exe.
- Although the free version is only a trial, EXE to MSI Converter Pro can convert the resulting EXE file to an MSI (Windows Installer Package) file.
- You can use the free NSSM command-line tool if you want to run a BAT file as a Windows Service. can help you convert the code in a BAT file to a PowerShell script.
Instead of searching for a BAT to SH (bash shell script) converter to use the commands in programs such as Bourne Shell and Korn Shell, try just rewriting the script using the Bash language. The structure of the two formats is rather different because the files are used in different operating systems. There is a Stack Overflow thread and this Unix Shell Scripting tutorial for some information that might help you translate the commands manually.
Usually, you can’t change a file extension (like BAT) to one that your computer recognizes and expect the newly renamed file to be usable. An actual file format conversion using one of the methods described above must take place in most cases. Given that BAT files are just text files with the .BAT extension, however, you can rename it to .TXT to open it with a text editor. Remember that doing a BAT-to-TXT conversion will prevent the batch file from executing its commands.
How to Save a .BAT File as a .TXT File
Instead of manually changing the file extension from BAT to TXT, you also can open the batch file in Notepad for editing and then save it to a new file, choosing .TXT as the file extension before saving instead of .BAT.
This is also what you need to do when making a new BAT file in Notepad, but in reverse: save the default text document as BAT instead of TXT. In some programs, you might have to save it in the All Files file type, and then put the .bat extension on it yourself.
Although rare, BAT files can contain viruses, just like most other file formats. Scan any file you download online with an antivirus tool to avoid malware.
Batch script is its own language. The main function of batch script is to automate repetitive commands.
Comments are lines of text that do not affect the execution of code. Comments typically include documentation such as the purpose of the BAT file. Use the REM (Remarks) command to add comments to BAT files.
Shutdown – s. To shut down with a 10-second timer, use shutdown -s -t 10. The shutdown command should be preceded by @echo off.