Tech Souls, Connected.

+1 202 555 0180

Have a question, comment, or concern? Our dedicated team of experts is ready to hear and assist you. Reach us through our social media, phone, or live chat.

Step-by-Step Guide to Writing and Executing Batch Files in Windows 10

How to Create and Run a Batch File on Windows 10

Batch files are a convenient way to automate tasks on your computer, and in this guide, we’ll demonstrate how to create and run them on Windows 10. A batch file is a special text file with a “.bat” extension containing a sequence of commands to be executed by the Command Prompt.

While you can manually type commands to perform tasks or modify system settings on Windows 10, batch files streamline this process by saving time and reducing the risk of errors. Additionally, you can use tools like PowerShell for more complex scripts, but batch files remain useful for many automation tasks.

This guide covers the steps to create and run batch files on Windows 10, including creating advanced scripts and scheduling them using Task Scheduler.

Creating a Batch File on Windows 10

Creating a batch file is simple and requires only a text editor like Notepad and basic command-line knowledge. Follow these steps to create both basic and advanced batch files.

Create a Basic Windows 10 Batch File

To create a basic batch file, follow these steps:

  1. Open Notepad:
  • Open Start, search for Notepad, and click the top result to open the text editor.
  1. Type the following lines:@ECHO OFF ECHO Hello World! Your first batch file was printed on the screen successfully. PAUSE
    • @ECHO OFF ensures the commands are executed without being displayed.
    • ECHO prints the specified text to the screen.
    • PAUSE keeps the window open after execution.
  2. Save the File:
  • Click File > Save As.
  • Name the script, for example, first_basic_batch.bat.
  • Ensure the file extension is .bat.

Double-click the saved file to run it. Alternatively, you can run it using Command Prompt, File Explorer, or Task Scheduler.

Create an Advanced Windows 10 Batch File

To create an advanced batch file with multiple commands, follow these steps:

  1. Open Notepad:
  • Open Start, search for Notepad, and click the top result.
  1. Type the following lines:@ECHO OFF :: This batch file details Windows 10, hardware, and networking configuration. TITLE My System Info ECHO Please wait... Checking system information. :: Section 1: Windows 10 information ECHO ========================== ECHO WINDOWS INFO ECHO ============================ systeminfo | findstr /c:"OS Name" systeminfo | findstr /c:"OS Version" systeminfo | findstr /c:"System Type" :: Section 2: Hardware information. ECHO ============================ ECHO HARDWARE INFO ECHO ============================ systeminfo | findstr /c:"Total Physical Memory" wmic cpu get name wmic diskdrive get name,model,size wmic path win32_videocontroller get name wmic path win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution :: Section 3: Networking information. ECHO ============================ ECHO NETWORK INFO ECHO ============================ ipconfig | findstr IPv4 ipconfig | findstr IPv6 START https://support.microsoft.com/en-us/windows/windows-10-system-requirements-6d4e9a79-66bf-7950-467c-795cf0386715 PAUSE
    • Commands are categorized into sections: Windows info, hardware info, and network info.
    • START opens the specified URL in the default web browser.
  2. Save the File:
  • Click File > Save As.
  • Name the script, for example, first_advanced_batch.bat.

Double-click the file to run it or use Command Prompt, File Explorer, or Task Scheduler.

Create an Actionable Windows 10 Batch File

For tasks that don’t require user interaction, such as mapping a network drive, follow these steps:

  1. Open Notepad:
  • Open Start, search for Notepad, and click the top result.
  1. Type the following command:net use z: \\PATH-NETWORK-SHARE\FOLDER-NAME /user:YOUR-USERNAME YOUR-PASSWORD
    • Replace \\PATH-NETWORK-SHARE\FOLDER-NAME with the network path and YOUR-USERNAME YOUR-PASSWORD with the appropriate credentials.
  2. Save the File:
  • Click File > Save As.
  • Name the script, for example, mount-z-network-drive.bat.

The batch file will map the network folder when executed, without opening a Command Prompt window.

Running a Batch File on Windows 10

There are several ways to run batch files on Windows 10: on-demand, at startup, or on a schedule.

Run Batch File On-Demand

You can run a batch file on-demand using Command Prompt or File Explorer.

Using Command Prompt

  1. Open Command Prompt:
  • Open Start, search for Command Prompt, right-click the top result, and select Run as administrator.
  1. Run the Batch File:
  • Type the command: C:\PATH\TO\FOLDER\BATCH-NAME.bat
  • Replace with the actual path and name of your batch file.

Using File Explorer

  1. Open File Explorer:
  • Browse to the folder containing the batch file.
  1. Run the File:
  • Double-click the batch file.
  • (Optional) Right-click and select Run as administrator if required.

Run Batch Files on Startup

To run a batch file at startup, follow these steps:

  1. Copy the Batch File:
  • Right-click the batch file and select Copy.
  1. Open the Startup Folder:
  • Press Windows key + R, type shell:startup, and click OK.
  1. Paste the Batch File:
  • Paste the file or create a shortcut to the batch file in the Startup folder.

Run Batch File with Task Scheduler

To run a batch file using Task Scheduler:

  1. Open Task Scheduler:
  • Open Start, search for Task Scheduler, and click the top result.
  1. Create a New Task:
  • Right-click Task Scheduler Library, select New Folder, name it (e.g., MyScripts), and click OK.
  1. Configure the Task:
  • Right-click the new folder, select Create Basic Task.
  • Follow the wizard to name the task, set the trigger, and select the batch file to run.
  • Click Finish.

The task will execute the batch file based on the configured schedule.

These steps ensure you can create and run batch files efficiently, automating various tasks on Windows 10. This guide is also applicable to older versions like Windows 8.1 and 7, and it can be referenced for Windows 11.

Share this article
Shareable URL
Prev Post

Boolean Logic: The Mathematical Foundation of Modern Technology

Next Post

Step-by-Step: How to Permanently Turn Off Microsoft Defender Antivirus on Windows 10

Read next
Whatsapp Join