When using Windows PC, you probably have used, come across or heard of a batch file. However, not many people can clearly tell what a batch file is, its use, or how it is run in Windows. This article will help you to understand batch files, why they are used, and how to use them.
Related: What is drivers in Windows 10 and how to troubleshoot drivers?
What is Batch File?
Simply put, a batch file is a special type of plain text file containing a multiple or a list of commands for the command line interpreter (cmd) to run. Batch files use .bat file extension and are only useful in Windows OS. In some instances, batch files are referred to as script files. The Windows command prompt can understand and execute batch file commands in a sequence to perform a given task.
Why Use Batch Files?
In Windows 10, you may use a batch file to perform various actions including loading programs, automate repetitive tasks, and change system settings among others. While you can perform these actions or input the commands every time you need to run them, a batch file saves you time and energy by automating the process. Besides, with a batch file, you can execute a bunch of processes without user intervention. Users may run a batch files to:
- Launch programs or run processes at startup.
- Schedule tasks such as file backups.
- Configure devices.
- Automate routines.
- Launch apps or websites.
Caution: Though batch files are very helpful, they can be used to perform malicious actions. Attackers can use batch files to execute commands that would harm your PC. Therefore, before you run a batch file, ensure that you know and trust the source.
Creating a Batch File
To create a batch file in Windows, you only need a plain text editor and cmd commands.
- Open “Notepad” or any other text editor such as Notepad ++ and type your commands.
- You may type commands to perform multiple tasks in a single file.
- Click the “File” menu, then save and type the name of the batch file by adding .bat at the end of the name.
- Click the “Save” button. You can identify the .bat file with a thumbnail with two gear icons.
How to Run Batch File in Windows 10?
You can use various methods on Windows 10 to run a batch file depending on how and when you want to execute the tasks.
Method 1: Run Batch File on Demand
You can run the file from file explorer or Windows Command Prompt to perform the tasks only when you need to.
From File Explorer
- In File Explorer, open the folder containing the batch file.
- Double click the file or right-click to run the file as an administrator if the task requires admin permission to execute.
From Windows Command Prompt
- Launch Command Prompt with the “Run as Admin” option.
- Change the directory to the folder containing your batch file “C:\[user]\[file location path]\”
- Then type the command the name of the file with or without the .bat extension and press Enter.
Method 2: How to Run Batch File During Startup?
If you want to execute the batch file whenever you sign in to Windows, you can do so with the following steps.
- Press the “Win + R” shortcut keys to open the Run utility. Type “shell: startup” and hit Enter on your keyboard.
- This will open the “Startup” folder.
- Copy and paste your batch file or its shortcut into this folder and then close.
- You can sign out your account and sign in again to verify that it works.
Method 3: Run Batch File With Task Scheduler
If you want to execute the task at a later time, you can use the Windows 10 Task Scheduler to run the batch file.
- Go to the Start menu and search for “Task Scheduler” and select the appropriate option from the result.
- Under the scheduler library on the left panel, create a folder for your task and click “Create Basic Task…” under the “Actions” section on the right-side panel.
- Enter the name and description (optional) of your task on the resulting wizard and then click “Next”.
- Set the task trigger depending on when you need the task to run and click the “Next” button.
- Under “Action” choose the “Start a program” option and continue to the next page.
- In the “Script” field, click “Browse”, navigate to the location where you save the batch file and choose the file.
- Verify the task details and click “Finish” to complete the process.
- Windows will automatically run the batch file at your specified time.
Batch files stores instructions to perform a specific task in Windows. You can use a batch file to automate routines, configure system settings and many other basic tasks. You can create and save a batch file and use any of the above methods to execute the file in Windows 10. The only major limitation is that batch files are exclusive to Windows PC.
Leave a Reply
Your email is safe with us.