Jump to content
  • How to create batch script files on Windows 11


    Karlston

    • 755 views
    • 7 minutes
     Share


    • 755 views
    • 7 minutes

    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

     

    rYrVDiNayLqAgXDWQpwnyC-970-80.jpg

    (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."

     

    PDaSkmpjZhDqXhwbFw3eUM-970-80.jpg

    (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

     

    eUNk7Cri7QtpA7e7Z4cp8X-970-80.jpg.webp

    (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 Enter: C:\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

     

    fUcHN2CcdiknyKCpjV6MKD-970-80.jpg

    (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.

     

    rsRgvTv3Wvd7oKkd7NMTQN-970-80.jpg

    (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 Enter: shell:startup
    5. Click the Paste button from the command bar in the Startup folder.

     

    Ecfp37HR8AM3QFvNzx6z9h-970-80.jpg

    (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.

     

     

    How to create batch script files on Windows 11

    • Like 1

    User Feedback

    Recommended Comments

    There are no comments to display.



    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.
    Note: Your post will require moderator approval before it will be visible.

    Guest
    Add a comment...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...