How to run bat file in cmd windows


Download Article

Easily run .BAT files in Windows and troubleshoot common problems


Download Article

  • Running from the Batch File’s Folder
  • |

  • Running from Anywhere
  • |

  • Troubleshooting
  • |

  • Other Ways to Run Batch Files
  • |

  • Expert Q&A
  • |

  • Warnings

If you need to run a batch file at the Windows Command Prompt, you’ll just need to know the location of the batch file. To run the file at the command line, simply type the full path to the batch file and press Enter. Or, if you don’t want to type the full path to the file, you can use the cd command to enter the folder containing the .BAT file, type the batch file’s name, and then press Enter. This wikiHow guide will teach you 2 simple ways to run a batch file from the Command Prompt in Windows, help you fix common errors, and show you a few other cool ways to run batch files on your PC.

Things You Should Know

  • Use the «cd» command to enter the folder that contains your batch file.
  • To run the batch file, type its name and press «Enter.»
  • You can also type the full path to the batch file from any folder to run batch files from anywhere.
  1. Image titled Run a Batch File from the Command Line on Windows Step 1

    1

    Open the Command Prompt. If your batch file performs administrative tasks, open Command Prompt as an administrator. If the batch file only requires access to files in your user account, you don’t need to start it as an administrator.

    • Press the Windows key on your keyboard.
    • Type cmd.
    • If your batch file doesn’t need administrator rights, click Command Prompt.
    • If your batch file does require administrator rights:
      • Right-click Command Prompt.
      • Select Run as administrator.
      • Click Yes.
  2. Image titled Run a Batch File from the Command Line on Windows Step 2

    2

    Type cd followed by the full path to your batch file’s folder. The cd command stands for «change directories.» For example:

    • If the file is at D:\Music\MP3s\Unsorted, you’d type cd D:\Music\MP3s\Unsorted.
    • If the batch file is on your desktop, you’d type cd \Users\YourLoginName\Desktop.
      • If you use OneDrive to automatically back up your personal files, you’d use cd \Users\YourLoginName\OneDrive\Desktop instead.
      • If you don’t know your login name, type cd \Users and press Enter. Then, type dir and press Enter to see a list of users.

    Advertisement

  3. Image titled Run a Batch File from the Command Line on Windows Step 3

    3

    Press Enter. This will move you into the folder containing your batch file.

    • Type dir and press Enter to see a list of all files in the current folder. You should see your batch file (ending with .bat) here.
  4. Image titled Run a Batch File from the Command Line on Windows Step 4

    4

    Type the name of the batch file and press Enter. For example, if your batch file is called program.bat, type program.bat and press Enter. This runs the batch file.

  5. Advertisement

  1. Image titled Run a Batch File from the Command Line on Windows Step 5

    1

    Get the full path to your batch file. If you want to run a batch file without using cd to enter its folder first, you’ll just need to know the full path to the file. For example, C:\Users\wikiHow\Scripts\mybatchfile.bat. Here’s an easy way to find the full path to your batch file:

    • Navigate to your batch file. If you’re not sure where you saved it, you can search for it.
    • If you’re using Windows 11, right-click the file and select Copy as path (Windows 11).
    • On Windows 10 and earlier, right-click the file and select Properties. Highlight the path next to «Location» and press Ctrl + C to copy it to your clipboard.
  2. Image titled Run a Batch File from the Command Line on Windows Step 6

    2

    Open the Command Prompt. If your batch file performs administrative tasks, open Command Prompt as an administrator. If it only requires access to files in your user account, you don’t need to start it as an administrator.

    • Press the Windows key on your keyboard.
    • Type cmd.
    • If your batch file doesn’t need administrator rights, click Command Prompt.
    • If your batch file does require administrator rights:
      • Right-click Command Prompt.
      • Select Run as administrator.
      • Click Yes.
  3. Image titled Run a Batch File from the Command Line on Windows Step 7

    3

    Type or paste the full path to your batch file. To paste the path you copied earlier, press Ctrl + V.

    • Alternatively, you can type the full path to your file manually (e.g., C:\Users\wikiHow\Scripts\mybatchfile.bat).
    • Because the .BAT extension is executable, you don’t need to type any commands before pasting or entering the path to the file.
  4. Image titled Run a Batch File from the Command Line on Windows Step 8

    4

    Press Enter to run the batch file. The batch file will now run. Any commands in the batch file will execute as specified in the script.

  5. Advertisement

  1. Image titled Run a Batch File from the Command Line on Windows Step 9

    1

    Running the batch file at the prompt just takes me to the next line. Depending on the commands in your batch file, you may not see confirmation or output when you run a .BAT file from Command Prompt. You’ll only see output if there’s a command in the batch file that’s supposed to display output.

    • For example, if the batch file is just working with files on your PC, such as moving, renaming, and/or deleting, you won’t see the commands as they run unless @echo on is at the top of the .BAT file.[1]
    • You can also add echo "your text here" to your batch file to display a custom message when run.
  2. Image titled Run a Batch File from the Command Line on Windows Step 10

    2

    I see «The syntax of the command is incorrect» when I run a batch file. This means that there’s an error with one of the commands in the batch file. The error could be due to missing or incorrect symbols, leaving out a flag required by a command, or even missing quotation marks around paths. Open the batch file in an editor like Notepad and inspect the code for errors.

  3. Image titled Run a Batch File from the Command Line on Windows Step 11

    3

    I’m getting the error «x is not recognized as an internal or external command.» This error also indicates an error in the batch file. But in this case, the error occurs because a command in the batch file is not recognized by Command Prompt. Fortunately, the error tells you exactly which command is failing, so it should be simple to fix.

    • For example, if a command in the .BAT file is misspelled or incorrect (e.g., «ifconfig» instead of «ipconfig»), or trying to start a program using its name instead of its full path.
  4. Image titled Run a Batch File from the Command Line on Windows Step 12

    4

    When I double-click a batch file, the window just closes. If double-clicking your .BAT file quickly opens and closes a Command Prompt window, it just means the batch file doesn’t have a «pause» at the end. If you want to keep the window open after the commands have run, just add «pause» to the end of the batch file.

    • Right-click the batch file.
    • Select Open with > Notepad (Windows 10) or Show more options > Edit (Windows 11).
    • Add «pause» to the last line of the batch file.
    • Save the file and run it again. Now, when you run the batch file, the window will stay open while displaying «Press any key to continue…» Once you press a key, the window will close.[2]
  5. Advertisement

  1. Image titled Run a Batch File from the Command Line on Windows Step 13

    1

    Double-click any .BAT file to run it instantly. If you don’t want to use the Command Prompt, you can easily run a batch file from any location on your Windows PC just by double-clicking it.

    • If double-clicking the batch file opens and closes a window without showing you any details, see this troubleshooting tip.
  2. Image titled Run a Batch File from the Command Line on Windows Step 14

    2

    Use the Run dialog. To call up a batch script from the Run dialog:

    • Press Windows key + R to open Run.
    • Click Browse.
    • Navigate to and select your batch file.
    • Click Open.
    • Click OK to run the batch file.
  3. Image titled Run a Batch File from the Command Line on Windows Step 15

    3

    Run the batch file at a specific time and date. Use Windows Task Scheduler to automatically run a batch file at the time and date of your choice. You can have the batch file run once or on a regular schedule.

    • Press the Windows key and type task scheduler.
    • Click Task Scheduler.
    • Expand the «Task Scheduler Library» folder.
    • Create a new folder: Right-click Task Scheduler Library, click New Folder…, type a name, and click OK.
    • Right-click your new folder and select Create basic task. Type a name for your task and click Next.
    • Choose when (and how often) you want the batch file to run. For example, if you want it to run at a certain date, select the date. Then, click Next.
    • Select Start a program, click Next, and then click Browse to select your .BAT file.
    • Click Finish. The batch file will now run automatically at the selected time and date.
  4. Image titled Run a Batch File from the Command Line on Windows Step 16

    4

    Run the batch file automatically when Windows starts. If you want the batch file to start automatically when your PC boots into Windows, you can copy or move the file to your Windows startup scripts folder. Here’s how:

    • Press Windows key + R to open the Run dialog.
    • Type shell:startup and click OK. This opens a File Explorer window to your Startup folder.
    • Drag or copy the .BAT file into the folder.
  5. Advertisement

Add New Question

  • Question

    After I run the batch script, it just opens another line and nothing happens.

    Nicole Levine, MFA

    Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions.

    Nicole Levine, MFA

    wikiHow Technology Writer

    Expert Answer

    Many batch scripts won’t display any confirmation that the commands have run. If you wrote the batch script yourself, you can switch the value of «echo» to «on» to display the commands at the prompt as they run. You can also add «pause» to the end of the script to make it prompt the user to press a key to continue. But in general, as long as you don’t see an error, that means the batch script executed properly.

  • Question

    What does this error mean? ‘.’ is not recognized as an internal or external command, operable program or batch file.

    wikiHow Staff Editor

    This answer was written by one of our trained team of researchers who validated it for accuracy and comprehensiveness.

    wikiHow Staff Editor

    wikiHow Staff Editor

    Staff Answer

    The batch script is trying to run «.» as a command, which is not a recognized command. Look for the extra period somewhere in the script and remove it.

  • Question

    How do I get out after I run my batch file ?

    wikiHow Staff Editor

    This answer was written by one of our trained team of researchers who validated it for accuracy and comprehensiveness.

    wikiHow Staff Editor

    wikiHow Staff Editor

    Staff Answer

    Just click the »’X»’ at the top corner of the command prompt window to close it. Or, if the batch script is hung on a process and not letting you go to the next line, you can press Ctrl + C to stop the batch file from running.

See more answers

Ask a Question

200 characters left

Include your email address to get a message when this question is answered.

Submit

Advertisement

Thanks for submitting a tip for review!

  • Never run a .BAT file as an administrator unless you know exactly what the file does. If the batch file is malicious, running it as an administrator could steal your data, install malware and viruses, and other dirty deeds.

  • Be careful when downloading .BAT files from the web or as email attachments. Make sure your PC is always protected by Microsoft Defender (or your preferred antivirus software) before running files from unknown sources.

Advertisement

About This Article

Article SummaryX

1. Press the Windows + R keys.
2. Click Browse.
3. Select the .bat file.
4. Click Open.
5. Click OK.

Did this summary help you?

Thanks to all authors for creating a page that has been read 343,904 times.

Is this article up to date?

Windows 10 run batch file
(Image credit: Future)

On Windows 10, a batch file typically has a «.bat» extension, and it is a special text file that contains one or multiple commands that run in sequence to perform various actions with Command Prompt.

Although you can type commands manually to execute a particular task or change system settings on Windows 10, a batch file simplifies the work of having to re-type the commands, saving you time and avoiding mistakes.

You can also use other tools like PowerShell to write even more advanced scripts. However, running batch files in Command Prompt is still relevant for executing commands to change settings, automate routines, and launch apps or web pages on your computer.

This guide will walk you through the steps to create and run a batch file on Windows 10. Also, we will outline the steps to create advanced scripts and rum them automatically on schedule using the Task Scheduler.

How to create a batch file on Windows 10

The process of writing a batch file is not complicated. You only need Notepad or another text editor and some basic knowledge of typing commands in Command Prompt. These instructions will help you create a basic and advanced batch file to query system settings.

Create basic Windows 10 batch file

To create a basic batch file on Windows 10, 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 a batch file: 

@ECHO OFF

ECHO Hello World! Your first batch file was printed on the screen successfully. 

PAUSE

The above script outputs the phrase, «Hello World! Your first batch file was printed on the screen successfully,» on the screen.

  • @ECHO OFF — Shows the message on a clean line disabling the display prompt. Usually, this line goes at the beginning of the file. (You can use the command without the «@» symbol, but it’s recommended to include it to show a cleaner return.)
  • ECHO — The command prints the text after the space on the screen.
  • PAUSE — Allows the window to stay open after the command has been executed. Otherwise, the window will close automatically as soon as the script finishes executing. You can use this command at the end of the script or after a specific command when running multiple tasks and wanting to pause between each line.

Windows 10 basic batch file

(Image credit: Future)
  1. Click the File menu.
  2. Select the Save as option.
  3. Confirm a name for the script — for example, first_basic_batch.bat.
  • Quick note: While batch files typically use the .bat file extensions, you can also find them using the .cmd or .btm file extensions.

Once you complete the steps, double-click the file to run it. Alternatively, you can use the steps below to learn how to run a batch file with Command Prompt, File Explorer, or Task Scheduler.

Create advanced Windows 10 batch file

To create an advanced Windows batch file with multiple commands, 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 a more advanced Windows 10 batch file:

@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 IPv4ipconfig | findstr IPv6

START https://support.microsoft.com/en-us/windows/windows-10-system-requirements-6d4e9a79-66bf-7950-467c-795cf0386715

PAUSE

The above script runs each line to query a series of system details, and the result will be divided into three categories, including «WINDOWS INFO,» «HARDWARE INFO,» and «NETWORK INFO.» Also, the «START» command will open the web browser in the official support page outlining the Windows 10 system requirements, which you can check against your information.

  • @ECHO OFF — Shows the message on a clean line disabling the display prompt. Usually, this line goes at the beginning of the file.
  • TITLE — Prints a custom name in the title bar of the console window.
  • :: — Allows writing comments and documentation information. These details are ignored when the system runs the batch file.
  • ECHO — Prints the text after the space on the screen.
  • START — Opens an app or website with the default web browser.
  • PAUSE — Tells the console window to stay open after running the command. If you do not use this option, the window will close automatically as soon as the script finishes executing.

Advanced script sample

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

After you complete the steps, double-click the .bat file to run it or use the steps below to execute the script with Command Prompt, File Explorer, or Task Scheduler.

Create actionable Windows 10 batch file

You can also write batch scripts for any task that does not require user interaction. For instance, to map a network drive, install an application, change system settings, and more.

To create a non-interactive batch file on Windows 10, use these steps:

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

In the command, replace the «\\PATH-NETWORK-SHARE\FOLDER-NAME» for the folder network path to mount on the device and «YOUR-USERNAME YOUR-PASSWORD» with the username and password that authenticates access to the network share. 

This example maps a network folder as a drive inside File Explorer using the «Z» drive letter: net use z: \\10.1.4.174\ShareFiles

  • Quick note: If you are accessing the files from another computer that uses a specific username and password, do not forget to use the /user: option with the correct credentials.

Map network drive script

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

Once you complete the steps, the batch file will map the network folder without opening a Command Prompt window.

We only demonstrate a script with a single command, but you can include as many as you like, as long as you write them one per line.

How to run a batch file on Windows 10

Windows 10 has at least three ways to write batch files. You can run them on-demand using Command Prompt or File Explorer. You can configure the script using the Task Scheduler app to run it on schedule. Or you can save the batch files in the «Startup» folder to let the system run them as soon as you sign into the account.

Run batch file on-demand

If you want to run a script on-demand, you can use File Explorer or Command Prompt.

Command Prompt

To run a script file with Command Prompt on Windows 10, 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 10 batch file and press Enter: C:\PATH\TO\FOLDER\BATCH-NAME.bat

In the command, make sure to specify the path and name of the script. 

This example runs the batch file located in the «scripts» folder inside the «Downloads» folder: C:\Users\UserAccount\Downloads\first_basic_batch.bat

Run batch file from Command Prompt

(Image credit: Future)

After you complete the steps, the console will return the results, and the window won’t close even if the script does not include the «PAUSE» command since you are invoking the script from within a console session that was already open.

File Explorer

To run a batch file with File Explorer, use these steps:

  1. Open File Explorer.
  2. Browse to the folder with the batch file.
  3. Double-click the script file to run it.
  4. (Optional) If a command in the batch file requires administrator privileges, you will have to run the script as an admin by right-clicking the file and selecting the Run as administrator option.

File Explorer run batch file as administrator

(Image credit: Future)
  1. Click the Yes button

Once you complete the steps, the script will run each command in sequence, displaying the results in the console window.

Run batch files on startup

Windows 10 also features a known folder called «Startup,» which the system checks every time it starts to run applications, shortcuts, and scripts automatically without the need for extra configuration.

To run a script on the Windows 10 startup, use these steps:

  1. Open File Explorer.
  2. Open the folder containing the batch file.
  3. Right-click the batch file and select the Copy option.
  4. Use the Windows key + R keyboard shortcut to open the Run command.
  5. Type the following command: shell:startup

Run shell startup command

(Image credit: Future)
  1. Click the OK button.
  2. Click the Paste option from the «Home» tab in the Startup folder. (Or click the Paste shortcut button to create a shortcut to the batch file.)

Configure script on startup folder

(Image credit: Future)

After you complete the steps, the batch file will execute automatically every time you log into your account.

Run batch file with Task Scheduler

To use Task Scheduler to run the batch file automatically at a specific time, use these steps:

  1. Open Start.
  2. Search for Task Scheduler and click the top result to open the app.
  3. Right-click the «Task Scheduler Library» branch and select the New Folder option.
  4. Confirm a name for the folder — for example, MyScripts.
  • Quick note: You don’t need to create a folder, but keeping the system and your tasks separate is recommended.
  1. Click the OK button.
  2. Expand the «Task Scheduler Library» branch.
  3. Right-click the MyScripts folder.
  4. Select the Create Basic Task option.

Task Scheduler create basic task

(Image credit: Future)
  1. In the «Name» field, confirm a name for the task — for example, SystemInfoBatch.
  2. (Optional) In the «Description» field, write a description for the task.
  3. Click the Next button.
  4. Select the Monthly option.
  • Quick note: Task Scheduler lets you choose from different triggers, including a specific date, during startup, or when a user logs in to the computer. In this example, we will select the option to run a task every month, but you may need to configure additional parameters depending on your selection.

Task trigger settings

(Image credit: Future)
  1. Click the Next button.
  2. Use the «Start» settings to confirm the day and time to run the task.
  3. Use the «Monthly» drop-down menu to pick the months of the year to run the task.

Task Scheduler date selection

(Image credit: Future)
  1. Use the «Days» or «On» drop-down menu to confirm the days to run the task.

Schedule batch file day of the month

(Image credit: Future)
  1. Click the Next button.
  2. Select the Start a program option to run the batch file.

Start a program action

(Image credit: Future)
  1. In the «Program/script» field, click the Browse button.
  2. Select the batch file you want to execute.

Task Scheduler batch file location

(Image credit: Future)
  1. Click the Finish button.

Once you complete the steps, the task will run the script during the configured time and date or action.

The above instructions are meant to schedule only a basic task. You can use these instructions to create a more customizable task with the Task Scheduler.

This guide focuses on Windows 10, but the same steps will also work for older versions, including Windows 8.1 and 7. Also, you can refer to these instructions if you have Windows 11 installed on your computer.

More Windows resources

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

  • Windows 11 on Windows Central — All you need to know
  • Windows 10 on Windows Central — All you need to know

All the latest news, reviews, and guides for Windows and Xbox diehards.

Mauro Huculak is technical writer for WindowsCentral.com. His primary focus is to write comprehensive how-tos to help users get the most out of Windows 10 and its many related technologies. He has an IT background with professional certifications from Microsoft, Cisco, and CompTIA, and he’s a recognized member of the Microsoft MVP community.

  1. HowTo
  2. Batch Howtos
  3. Run Batch (.bat) File in CMD

MD Aminul Islam
Jan 30, 2023
May 21, 2022

  1. Run Batch (.bat) File in CMD by Direct Click
  2. Run Batch (.bat) File in CMD by Providing the Direct Location to the File
  3. Run Batch (.bat) File in CMD Using the Change Directory (CD) Command

Run Batch (.bat) File in CMD

This article will show how we can run a Batch file, .bat, using CMD.

There are three ways to run a Batch file. Let’s discuss them in the following sections.

Run Batch (.bat) File in CMD by Direct Click

In this way, you only need to go to your file location and double-click on it. But in this way, the file runs and immediately closes when its task finishes.

So, this way is not preferable if your Batch Script doesn’t show any output at the end.

Run Batch (.bat) File in CMD by Providing the Direct Location to the File

In this way, you need to provide the exact file location of the command. In CMD, type the exact location with filename on double quote like the following.

"G:\YOUR_DIRECTORY\Test_File.bat"

Run Batch (.bat) File in CMD Using the Change Directory (CD) Command

In this way, you have to locate your location using the change directory (cd) command and directly put the name of your file, as shown below.

CD "G:\YOUR_DIRECTORY\"
Test_File.bat

All of the method we discussed above is only for Windows CMD.

MD Aminul Islam avatar
MD Aminul Islam avatar

Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.

LinkedIn

Related Article — Batch Script

  • Run Multiple Commands Simultaneously in Batch Script
  • Extract or Unzip File in Batch Script
  • Run Batch Script in C#
  • Replace Text From File in Batch Script
  • Run Batch Script in Silent Mode
  • Download File From URL in Batch Script
  • Home
  • News
  • How To Create & Run A Batch File On Windows 10

By Sarah |
Last Updated

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 OFF

ECHO Congratulations! Your first batch file executed successfully.

PAUSE

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.

Simple bat file

There’s another way to open the Notepad window:

  1. Click on the Cortana search icon/box on taskbar.
  2. Type notepad and select Notepad from the result.

Notepad

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.

4 Ways To Recover Notepad File On Win 10 Quickly!

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 off

echo Hello this a test batch file

pause

dir c:\windows

pause

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:

  1. Open File Explorer on your Windows 10.
  2. Navigate to the drive and folder that include the Windows batch file.
  3. Just double click on the batch file to run it.

Note: Some commands require the administrator privileges, so you need to run the .bat file as administrator: right click on the file -> choose Run as administrator -> click Yes.

Run Windows batch file in File Explorer

Click here if your File Explorer is not responding or has stopped working.

Run a batch file from Command Prompt:

  1. Open Windows search and type cmd.
  2. Right click on Command Prompt and choose Run as administrator.
  3. Type C:\Users\folder location\filename.bat and hit Enter.

Run as administrator

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.

The Command Prompt tool can also be used to recover files on Windows 10.

About The Author

Position: Columnist

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.

"F:\- Big Packets -\kitterengine\Common\Template.bat" maybe prefaced with call (see call /?). Or Cd /d "F:\- Big Packets -\kitterengine\Common\" & Template.bat.


CMD Cheat Sheet

  • Cmd.exe

  • Getting Help

  • Punctuation

  • Naming Files

  • Starting Programs

  • Keys

CMD.exe

First thing to remember its a way of operating a computer. It’s the way we did it before WIMP (Windows, Icons, Mouse, Popup menus) became common. It owes it roots to CPM, VMS, and Unix. It was used to start programs and copy and delete files. Also you could change the time and date.

For help on starting CMD type cmd /?. You must start it with either the /k or /c switch unless you just want to type in it.

Getting Help

For general help. Type Help in the command prompt. For each command listed type help <command> (eg help dir) or <command> /? (eg dir /?).

Some commands have sub commands. For example schtasks /create /?.

The NET command’s help is unusual. Typing net use /? is brief help. Type net help use for full help. The same applies at the root — net /? is also brief help, use net help.

References in Help to new behaviour are describing changes from CMD in OS/2 and Windows NT4 to the current CMD which is in Windows 2000 and later.

WMIC is a multipurpose command. Type wmic /?.


Punctuation

&    seperates commands on a line.

&&    executes this command only if previous command's errorlevel is 0.

||    (not used above) executes this command only if previous command's 
errorlevel is NOT 0

>    output to a file

>>    append output to a file

<    input from a file

2> Redirects command error output to the file specified. (0 is StdInput, 1 is StdOutput, and 2 is StdError)

2>&1 Redirects command error output to the same location as command output. 

|    output of one command into the input of another command

^    escapes any of the above, including itself, if needed to be passed 
to a program

"    parameters with spaces must be enclosed in quotes

+ used with copy to concatenate files. E.G. copy file1+file2 newfile

, used with copy to indicate missing parameters. This updates the files 
modified date. E.G. copy /b file1,,

%variablename% a inbuilt or user set environmental variable

!variablename! a user set environmental variable expanded at execution 
time, turned with SelLocal EnableDelayedExpansion command

%<number> (%1) the nth command line parameter passed to a batch file. %0 
is the batchfile's name.

%* (%*) the entire command line.

%CMDCMDLINE% - expands to the original command line that invoked the
Command Processor (from set /?).

%<a letter> or %%<a letter> (%A or %%A) the variable in a for loop. 
Single % sign at command prompt and double % sign in a batch file.

\\ (\\servername\sharename\folder\file.ext) access files and folders via UNC naming.

: (win.ini:streamname) accesses an alternative steam. Also separates drive from rest of path.

. (win.ini) the LAST dot in a file path separates the name from extension

. (dir .\*.txt) the current directory

.. (cd ..) the parent directory


\\?\ (\\?\c:\windows\win.ini) When a file path is prefixed with \\?\ filename checks are turned off. 

Naming Files

< > : " / \ | Reserved characters. May not be used in filenames.



Reserved names. These refer to devices eg, 

copy filename con 

which copies a file to the console window.

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, 

COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, 

LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9

CONIN$, CONOUT$, CONERR$

--------------------------------

Maximum path length              260 characters
Maximum path length (\\?\)      32,767 characters (approx - some rare characters use 2 characters of storage)
Maximum filename length        255 characters

Starting a Program

See start /? and call /? for help on all three ways.

There are two types of Windows programs — console or non console (these are called GUI even if they don’t have one). Console programs attach to the current console or Windows creates a new console. GUI programs have to explicitly create their own windows.

If a full path isn’t given then Windows looks in

  1. The directory from which the application loaded.

  2. The current directory for the parent process.

  3. Windows NT/2000/XP: The 32-bit Windows system directory. Use the
    GetSystemDirectory function to get the path of this directory. The
    name of this directory is System32.

  4. Windows NT/2000/XP: The 16-bit Windows system directory. There is no
    function that obtains the path of this directory, but it is
    searched. The name of this directory is System.

  5. The Windows directory. Use the GetWindowsDirectory function to get
    the path of this directory.

  6. The directories that are listed in the PATH environment variable.

Specify a program name

This is the standard way to start a program.

c:\windows\notepad.exe

In a batch file the batch will wait for the program to exit. When
typed the command prompt does not wait for graphical
programs to exit.

If the program is a batch file control is transferred and the rest of the calling batch file is not executed.

Use Start command

Start starts programs in non standard ways.

start "" c:\windows\notepad.exe

Start starts a program and does not wait. Console programs start in a new window. Using the /b switch forces console programs into the same window, which negates the main purpose of Start.

Start uses the Windows graphical shell — same as typing in WinKey + R (Run dialog). Try

start shell:cache

Also program names registered under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths can also be typed without specifying a full path.

Also note the first set of quotes, if any, MUST be the window title.

Use Call command

Call is used to start batch files and wait for them to exit and continue the current batch file.

Other Filenames

Typing a non program filename is the same as double clicking the file.


Keys

Ctrl + C exits a program without exiting the console window.

For other editing keys type Doskey /?.

  • and recall commands

  • ESC clears command line

  • F7 displays command history

  • ALT+F7 clears command history

  • F8 searches command history

  • F9 selects a command by number

  • ALT+F10 clears macro definitions

Also not listed

  • Ctrl + or Moves a word at a time

  • Ctrl + Backspace Deletes the previous word

  • Home Beginning of line

  • End End of line

  • Ctrl + End Deletes to end of line

  • How to open emoji windows 10
  • How to recover deleted files windows 10
  • How to install wsl on windows 10
  • How to install windows powershell
  • How to open disk management windows 10