How To Make A Batch File

I have seen this question asked many times on the forums here at PCMech. Sometimes, what one takes for granted, makes others scratch their head so I figured this is worth a tip posting.

Suppose you wanted a batch file to simply print the name of your computer. The command you would run would be the following:

echo %computername%

Here is how to make the above command a batch file:

  1. Open Notepad (you can use any text editor, but I am going to assume Notepad).
  2. Type/paste the commands you want to be in your batch file.
  3.  Select File > Save As.
  4. In the dialog, browse to the location where you want to save the batch file.
  5. Change the “Save as type” option to “All Files (*.*)” and then enter the file name ending with “.bat”, for example: MyComputerName.bat
  6. Alternate to step 5, you can enter the file name “MyComputerName.bat” (including the quotes) and this will ignore the Save as type setting.
  7. Click Save.

There you have it. You should now have a batch file in all its glory.

Free eBook!

Like what you read?

If so, please join over 28,000 people who receive our exclusive weekly newsletter and computer tips, and get FREE COPIES of 5 eBooks we created, as our gift to you for subscribing. Just enter your name and email below:

Post A Comment Using Facebook

  • Luis R.

    Is there any difference with batch files with the .cmd extension?

  • Jason Faulkner

    In short, yes… it has to do with OS support. Always use a batch file where possible.

    Rather than me explain it, Wikipedia has done a good job:
    http://en.wikipedia.org/wiki/Batch_file

  • Pingback: Windows Batch Script To Backup Data » PCMech

  • totalcontrol

    ok so we can make a batch file but how can we get windows to automatically open this batch file?

    • drake

      u go to [MY COMPUTER]and then u go to [DOCUMENTS AND SETTINGS] then go to [STARTUP]and then u place the file there and it will start up every time you start up the computer.

  • Kamrul

    Thanks

  • Pingback: Batch Script To Open Multiple Programs At Once | PCMech

  • Roger

    There are tools handier than Notepad. For example, Notepad++. I prefer to use Dr.Batcher ( http://www.drbatcher.com ). It’s a tool designed especially to create batch files. Unfortunately, it’s not freeware :(

  • somebody

    @echo off
    title Matrix
    cls
    color 2
    :start
    echo %random% %random% %random% %random% %random% %random%
    goto start
    \\this is the way to make the matrix

What’s Your Preference?

Daily Alerts

Each day we send out a quick email to thousands of PCMECH readers to notify them of new posts. This email is just a short, plain email with titles and links to our latest posts. You can unsubscribe from this service at any time.

You can subscribe to it by leaving your email address in the following field and confirming your subscription when you get an email asking you to do so.

Enter your email address for
Daily Updates:

Weekly Newsletter

Running for over 6 years, the PCMECH weekly newsletter helps you keep tabs on the world of tech. Each issue includes news bits, an article, an exclusive rant as well as a download of the week. This newsletter is subscribed to by over 28,000 readers (many who also subscribe to the other option) - come join the community!

To subscribe to this weekly newsletter simply add your email address to the following field and then follow the confirmation prompts. You will be able to unsubscribe at any time.

Enter your email address for
Free Weekly Newsletter: