Get all your news in one place.
100’s of premium titles.
One app.
Start reading
Windows Central
Windows Central
Technology
Mauro Huculak

How to create batch script files on Windows 11

Windows 11 create and run batch files

A batch file refers to those text files that usually end with a ".bat" extension that contains multiple commands that the system can run in sequence from the Command Prompt to perform different tasks.

On Windows 11, you can use a batch file to quickly make system changes, query system information, automate routines, and launch apps while reducing the steps, mistakes, and time it could take to type the commands or perform specific actions. 

Although you can always create more comprehensive scripts with PowerShell, batch files you can run on Command Prompt are still useful and easier to craft to perform an extended range of tasks.

This how-to guide will walk you through the different ways in which you can create and run a batch file on Windows 11.

How to create batch files on Windows 11

You can quickly write batch files with any text editor, such as Notepad or Visual Studio Code. You will only need some basic Command Prompt skills. 

This guide will show you three examples. The first one will help you build a basic batch file with three lines of code. The second example is a little more advanced, outlining the basics of running multiple commands. Finally, the third example demonstrates that you can perform different actions.

Compose basic batch file

To write a basic batch file on Windows 11, use these steps:

  1. Open Start.
  2. Search for Notepad and click the top result to open the text editor.
  3. Type the following lines of code in the text file: 

@ECHO OFF

ECHO Hello World! This is my first batch file created on Windows 11. 

PAUSE

(Image credit: Future)

The above code will output the "Hello World! This is my first batch file created on Windows 11" message on the screen.

  1. Click the File menu and select the Save as option.
  2. Confirm a name for the script – for example, basic_batch.bat.

Once you complete the steps, double-click the file to run the script.

You will typically find batch files with the ".bat" extension, but it's also possible to use the ".cmd" or ".btm" file extensions.

Here's a break down of the commands:

  • @ECHO OFF — Disables the display prompt and shows content in a clean line.
  • ECHO — Prints the text after the space on the screen.
  • PAUSE — Keeps the window open after running the commands. If you don't use this option, the prompt will close automatically after the script finishes. You can use this command at the end of the script or after a specific command to insert a break on each line.

Compose advanced batch file

To create an advanced batch script, use these steps:

  1. Open Start.
  2. Search for Notepad and click the top result to open the text editor.
  3. Type the following lines in the text file to create an advanced script:

@ECHO OFF 

:: This batch file reveals Windows 11, hardware, and networking configuration.

TITLE My Computer Information

ECHO Checking system information...

:: Section 1: Windows 11 details

ECHO ==========================

ECHO WINDOWS 11 INFO

ECHO ============================

systeminfo | findstr /c:"OS Name"

systeminfo | findstr /c:"OS Version"

:: Section 2: Hardware details

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: Network details.

ECHO ============================

ECHO NETWORK INFO

ECHO ============================

ipconfig | findstr IPv4ipconfig | findstr IPv6

PAUSE

This script executes multiple system commands in sequence and outputs the computer information in three different categories, including "Windows details," "hardware details," and "network details."

(Image credit: Future)
  1. Click the File menu and select the Save as option.
  2. Type a name for the script — for example, advanced_batch.bat.

After you complete the steps, running the batch file will open a Command Prompt console outputting the results for each command. 

Here's a breakdown of the commands:

  • @ECHO OFF — Disables the display prompt and shows content in a clean line.
  • TITLE — Renders a custom name for the window title bar.
  • :: — Ignores the contents of the line. Usually, it's used to write comments and documentation information.
  • ECHO — Prints the text after the space on the screen.
  • PAUSE — Keeps the window open after running the commands.

Compose actionable batch file

One of the most common reasons to use scripts is to automatize different tasks to make system changes, such as connecting a network drive, installing an application, or changing system settings.

To create a script to change system settings on Windows 11, use these steps:

  1. Open Start.
  2. Search for Notepad and click the top result to open the app.
  3. Type the following command in the text editor: net use z: \\PATH-NETWORK-SHARE\FOLDER-NAME /user:USERNAME PASSWORD

In the command, replace the "\\PATH-NETWORK-SHARE\FOLDER-NAME" for the folder network path to mount on the device and "USERNAME PASSWORD" with the username and password that authenticates access to the network share. This example maps a network folder using "Z" as the drive letter: net use z: \\10.1.4.57\ShareFiles

(Image credit: Future)
  1. Click the File menu and select the Save as option.
  2. Confirm a name for the script — for example, network-drive-batch.bat.

Once you complete the steps, this particular batch file will map a network on File Explorer.

How to run batch files on Windows 11

On Windows 11, you can run batch files in at least three ways from Command Prompt, File Explorer, or automatically during startup.

Run script from Command Prompt

To run a batch file from Command Prompt on Windows 11, use these steps:

  1. Open Start.
  2. Search for Command Prompt, right-click the top result, and select the Run as administrator option.
  3. Type the following command to run a Windows 11 batch file and press EnterC:\PATH\TO\FOLDER\BATCH.bat

In the command, specify the path and name for your script. This example runs the batch file located in the "scripts" folder inside the "Downloads" folder: C:\Users\ACCOUNT\Downloads\basic_batch.bat

(Image credit: Future)

After you complete the steps, the batch file will run and display the results in the console. Since you opened Command Prompt manually, it won't close automatically if the script doesn't include the "Pause" option.

Run script from File Explorer

To run a script file from File Explorer on Windows 11, use these steps:

  1. Open File Explorer.
  2. Browse to the folder with the batch file.
  3. Right-click the file and select the Open option to run it.
  4. (Optional) Right-click the file and select the Run as administrator option if elevation is required.
(Image credit: Future)

Once you complete the steps, the batch file will run and execute every command. If you have specified the "Pause" option, the window will remain open. Otherwise, it'll close immediately after completing the sequence of commands.

Run script from Startup

To run a batch file on startup, use these steps:

  1. Open File Explorer.
  2. Open the folder with the batch file.
  3. Right-click the file and select the Copy option.
  4. Type the following command in the address bar and press Entershell:startup
  5. Click the Paste button from the command bar in the Startup folder.
(Image credit: Future)

After you complete the steps, Windows 11 will run the script every time the computer starts, and the user logs in to the account.

More resources

For more helpful articles, coverage, and answers to common questions about Windows 10 and Windows 11, visit the following resources:

Sign up to read this article
Read news from 100’s of titles, curated specifically for you.
Already a member? Sign in here
Related Stories
Top stories on inkl right now
Our Picks
Fourteen days free
Download the app
One app. One membership.
100+ trusted global sources.