Pinterest Stumbleupon Whatsapp
Ads by Google

Before Windows became our favorite GUI Run DOS Applications Through A GUI Interface With DOSShell Run DOS Applications Through A GUI Interface With DOSShell Read More , everything was done using commands. Some of our readers may remember using MS-DOS commands to complete the smallest of tasks. These days, you can still use commands to automate tasks and speed up your productivity Boost Office Productivity with 10 Tweaks Backed by Science Boost Office Productivity with 10 Tweaks Backed by Science Productivity runs deeper than your to-do list. Being productive is tightly linked to feeling good and simple tweaks to your environment can unleash unknown potential. We show you where to start. Read More .

If you have a number of boring and repetitive tasks, a batch file is exactly what you’re looking for. Instead of manually executing tasks, a single batch file can be written to take care of everything.

The Basics: Creating a Batch File

Batch files are written in plain text. You can use whichever plain text editor you like, but the standardized Notepad does the job just fine. If you’re creating really complex programs, it can be handy to have the additional features of Notepad++ 3 Handy Built-In Notepad++ Features For Beginners [Windows] 3 Handy Built-In Notepad++ Features For Beginners [Windows] This summer, I’ve used Notepad++ for my internship quite a bit, so I can see why almost all developers and programmers I know actually prefer it, not to mention, the thousand of Notepad++ fans that... Read More , but for our examples, we will stick with what we know.

Each example batch file provided has been tested using Notepad Notepad Not Doing The Trick? Try Out The Lightweight Alternatives Xint & Subpad Notepad Not Doing The Trick? Try Out The Lightweight Alternatives Xint & Subpad Read More . Once we’ve finished inputting our commands, we’ll head to Save As, and give the file an appropriate name. Once saved, we can change the file extension from .txt to .bat, and press Enter. You should notice the file icon immediately change to an application window featuring a cog.

Tasks You Can Automate

Here are a few really useful batch commands for you to play around with, and some short descriptions of what each command syntax and parameter can do 15 CMD Commands Every Windows User Should Know 15 CMD Commands Every Windows User Should Know The command prompt is an antiquated tool from an era of text-based input. But some commands remain useful and Windows 8 even added new features. Find out which ones. Read More .

Ads by Google

1. Open Multiple Programs

This one will let you start multiple programs with a single click. First, identify the programs or files you want to open simultaneously. In this instance, I’ll be opening Chrome, a Word file This Is How You Can Get Microsoft Word for Free This Is How You Can Get Microsoft Word for Free Do you really want the entire Microsoft Office suite? If all you need is Word without the fancy features, Microsoft will give it to you for free. Here is how. Read More I’m working on, and VMware Player.

Open a new text file and type:

@echo off
cd "C:\Program Files\Google\Chrome\Application\"
start chrome.exe
start – "C:\Program Files\Microsoft Office\Office15\WINWORD.EXE"
"C:\Work\MUO\How to Batch Rename.docx"
cd "C:\Program Files (x86)\VMware\VMware Player"
start vmplayer.exe

Of course, you can add numerous applications and files to this list. For super-opening powers, you can pair this batch file with a hotkey.

Windows Start Multiple Files Batch

The commands we have used here are:

  • @echo displays the command currently being executed in a command shell. We turned this off.
  • cd changes the directory
  • start does the obvious, and starts the program

2. Delete Files Older Than

We can also use a batch file to delete files older than a user-set amount of days. This can be used to delete one specific file type, or a group of files in a folder, so long as they meet the specifications in the batch file. Our first example will delete files in the specified folder older than three days:

forfiles /p "C:\some\file\name\here" /s /m * /d -3 /c "cmd /c del @path"

Our second example will delete only files with the extension .docx, again older than three days:

forfiles /p "C:\some\file\name\here" /s /m * .docx /d -3 /c "cmd /c del @path"

The commands and switches we have used here are:

  • forfiles allows us to use commands for each file in a location i.e. the commands will apply to each file fitting the command arguments
  • /p details the path to start searching i.e. the directory you want to delete the files from
  • /s instructs the command to search sub-directories
  • /m instructs the command to use the given search mask. We used the wildcard operator “*” in our first example, and specified .docx in the second
  • /d-3 is the time setting. Increase or decrease depending on your requirements
  • /c del @path is the delete aspect of the command

3. Backing Up Your System

We can use batch files to back up specific folders, or as part of a wider backup operation How System Restore & Factory Reset Work in Windows 10 How System Restore & Factory Reset Work in Windows 10 Space wasted to a recovery partition is a thing of the past. System Restore and Factory Reset have improved in Windows 10. We show you how it works. Read More . Most people have backups and system restore points setup as standard, but sometimes it pays to make a couple of copies of anything that might make you cry if it were deleted. I’m going to show you one very simple method and another slightly more advanced version.

Windows Batch Backup Test

Method #1

Open Notepad. Type the following, following the instructions:

@echo off
ROBOCOPY C:\your\filename\goes\here C:\your\backup\location\goes\here /LOG:backuplog.txt

Save the file, then rename to systembackup.bat, and press Enter.

This method works well when backing up individual folders, but isn’t entirely practical for anything more complex. The commands used here are:

  • ROBOCOPY stands for Robust File Copy, which replaced when Windows Vista was released

Method #2

This time we will build a longer string of folders we want to back up, including your Outlook address book, and your system registry.

@echo off
:: variables
set drive=X:\Backup
set backupcmd=xcopy /s /c /d /e /h /i /r /y
echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"
echo ### Backing up Favorites...
%backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"
echo ### Backing up email and address book (Outlook Express)...
%backupcmd% "%USERPROFILE%\Application Data\Microsoft\Address Book" "%drive%\Address Book"
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Identities" "%drive%\Outlook Express"
echo ### Backing up email and contacts (MS Outlook)...
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook"
echo ### Backing up the Registry...
if not exist "%drive%\Registry" mkdir "%drive%\Registry"
if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg"
regedit /e "%drive%\Registry\regbackup.reg"
echo Backup Complete!

A little explanation to what’s going on here: First, we set the location we want the files to be copied to – “set drive=X:\Backup” – followed by the backup command we are going to use – xcopy. Following the xcopy command is a string of parameters telling the batch file to perform a number of tasks:

  • /s copies system files
  • /c carries out the command specified by the string, then terminates
  • /d enables drive and directory changes
  • /e copies empty directories
  • /h copies hidden files
  • /i if destination doesn’t exist, and you’re copying more than one file, /i assumes the destination must be a directory
  • /r overwrites read-only files
  • /y suppresses prompts confirming you want to overwrite read only files

To add more folders to the batch file, use the following syntax:

%backupcmd% "...source directory..." "%drive%\...destination dir..."

We’ve selected a number of folders to copy, but you might note they are all part of your USERPROFILE. If you just want to backup the entire folder, you can use this command, assuming the same “set drive” and “set backupcmd” are in use:

%backupcmd% "%USERPROFILE%" "%drive%\%UserName% - profile"

4. Change Your IP Address

Most of the time your laptop will use a dynamic IP What's an IP Conflict, and How Do You Resolve It? What's an IP Conflict, and How Do You Resolve It? Have any of your devices ever displayed an error message pertaining to an IP address conflict? Read More address to connect to the Internet. Sometimes, you might be required to use a static IP What Is A Static IP Address, How Do I Get One & Its Advantages / Disadvantages What Is A Static IP Address, How Do I Get One & Its Advantages / Disadvantages Read More , for instance at your workplace, school, or other “official” locations. Sure, you could manually change it, but if it’s somewhere you visit regularly, why not make a batch file to do the work for you?

For this we’ll create two files: one to make it static, and another to change it back to dynamic.


You should type the following for your static batch file:

netsh interface ip set address "LAN" static "" "" ""

Where the first series of “x’s” is your required static IP, the second is the network/subnet mask, and the third is your default gateway.


This batch file will return your network adaptor settings to a dynamic setup:

netsh int ip set address name = "LAN" source = dhcp

While neither of these files are doing anything by batch, just having those files can be a timesaver. If you have more than one network to connect to, copy the first file and alter the details.

5. Make Your Kids Go to Bed

My kids aren’t old enough to be playing video games in the middle of the night, but I remember my own tactics against my parents so I could play Championship Manager 2 Top 5 Football (Soccer) Games You've Probably Never Played But Should Top 5 Football (Soccer) Games You've Probably Never Played But Should If you feel as though you've played the latest, high-profile titles to death, there are alternatives for the armchair pro tired of FIFA, PES, Football Manager, and the rest. Read More into the small hours of the morning. Luckily, my parents didn’t know about using commands to control my actions. Try this:

@echo off
If %time%==23:30:00.00 goto :X
shutdown.exe /s /f/ t/ 120 /c "GO TO BED RIGHT NOW!!!"

Here, the computer constantly checks to see if the time is half-past eleven. When the time correlates, the message “GO TO BED RIGHT NOW!!!” will display, along with the 120s countdown timer. The 120s should be enough time to save whatever game they are playing, or their work, before the computer shuts down.

To stop this countdown, press Win+R.

Of course, don’t tell the children this.

6. Batch Rename & Mass Delete

I’ve written a more extensive article dealing with batch file renaming and deletion How to Batch Rename & Mass Delete Files in Windows How to Batch Rename & Mass Delete Files in Windows Are you pulling your hair out over how to batch rename or delete hundreds or thousands of files? Chances are, someone else is already bald and figured it out. We show you all the tricks. Read More , so I won’t explore this one too much, but batch files can be used to automate these sometimes tedious tasks. Check out the article for some extended batch commands, and get bulk deleting straight away.

Bonus: Pokémon!

So this has nothing to do with productivity 5 Habits Farmers Have That Can Boost Your Own Productivity 5 Habits Farmers Have That Can Boost Your Own Productivity Learning how to grow your level of efficiency from generations of men and women who grow things will teach you how to stick to your deadlines no matter what. Read More , and if you’re susceptible to Pokémon-related gaming addictions Prove Your Pokémon Mastery With These Difficult Challenges Prove Your Pokémon Mastery With These Difficult Challenges These in-game and fan made achievements will keep you playing long after the credits roll. Read More , maybe don’t download and play this. If not, you can grab this text-based adventure right here.

Pokemon Batch File

Whetted Your Appetite?

These are just six batch files you can create to automate tasks on your system. If you learn a little more Better Than Batch: A Windows Scripting Host Tutorial Better Than Batch: A Windows Scripting Host Tutorial Read More , you’ll be able to accomplish unheralded amounts of activities on your system between batch files and the Command Prompt. And if that doesn’t suit you, you could always take a look at the Windows PowerShell Command Prompt vs. Windows PowerShell: What's the Difference? Command Prompt vs. Windows PowerShell: What's the Difference? Windows users can get by without using either the Command Prompt or PowerShell. But with Windows 10 and new features around the corner, maybe it's about time we learned. Read More .

What are your favorite batch files? What do you automate to shave precious minutes from your day? Let us know below!

  1. Amit
    September 14, 2016 at 11:42 am

    Can you help me with the codes which can be used to restart the system tomorrow on specific time ?

    Also when it should close all the running apps and shut down.

    I dont know codes at all and this will help me alot.

  2. Mike
    September 12, 2016 at 1:23 am

    I've saved hundreds, probably thousands, of man hours writing programs that write batch files.

  3. d o
    September 11, 2016 at 4:39 pm

    At my last job they had a girl creating folders manually every week for dates. I created a batch script that let you type in the year and it created the whole years worth of folders for them for free. They gave me a warning and let me go at the end of my contract. I also got a warning for asking for a second copy of Acrobat so we could do more work, but they eventually purchased another copy of Acrobat, 5 months after I got let go.

  4. Alpha
    September 9, 2016 at 3:01 am

    Is there any tools, batch or script that would allow me to point the location where all a users PST files are kept and will map those pst files at one time rather than mapping each and every pst file one at a time.

    (Example) If the users has multiple PST files mapped in Outlook where they store emails
    based on certain criteria, many of the users have 10, 20 and even 50 individual PST
    files mapped in Outlook. All of the users PST files are store in computer local drive.

    Does anyone know is there such a freeware utility, or is there any batch and script file to be able to execute the task?

  5. Vijay Pcvark
    August 9, 2016 at 12:32 pm


  6. Vijay Pcvark
    August 9, 2016 at 12:16 pm


  7. Sid
    July 25, 2016 at 8:43 pm

    I have one annoying site that needs me to enter my password everytime it opens. How can i automate my password by using this.

  8. Kannon Yamada
    May 15, 2016 at 10:12 pm

    I regret not reading this article earlier. This is really great stuff. Thanks Gavin!

  9. bromberg
    February 4, 2016 at 5:30 am

    I thought PowerShell was meant for the corporate server environment. If not, how about an article on PowerShell uses for the PC home user?

    • Gavin Phillips
      February 15, 2016 at 2:41 pm

      No, home users can make use of the PowerShell for all sorts of tasks. There is an upcoming article detailing some of these, so be sure to keep an eye out for it. Thanks for reading!

      • dan
        February 16, 2016 at 4:22 am

        I look forward to my daily MUO newsletters and using PowerShell for home PC tasks will get me into some fun and useful projects. Can't wait!

  10. Joe O'Loughlin
    February 2, 2016 at 12:09 pm

    Please tell me how to print this article. I've tried several different tactics but none have been successful. I also tried to email the link to the article to myself but the resulting item couldn't be printed in any readable form. I've tried several of the available screen capture items but have not found one that does the job.

    • Fik of borg
      February 2, 2016 at 1:00 pm

      There are several plugins and extensions to turn web pages printables, but the most inmediate way to do it would be to do it manualliy: Select the text, copy, paste in notepad to wipe the formatting, copy from notepad and paste in your word processor to format the text according to your needs before printing (to PDF, don't waste paper or ink!).
      Of course, after all that you would have the text memorized ...

    • Kelsey Tidwell
      February 2, 2016 at 5:52 pm

      Have you tried Evernote Clearly? There should be an extension for any browser you're using. Let it do its formatting magic, then you can right click, print or copy, paste into a word processor, depending on your browser.

      Oh...I read that Clearly is going away, so get it while you can :)

      Happy Groundhog Day if you're in the States, and Happy Groundhog Day if you're not!

    • Gavin Phillips
      February 15, 2016 at 2:45 pm

      Hi Joe. Hopefully you've been able to use Fik of borg's Print to PDF idea, which should work absolutely fine. If you don't want to reformat, just head to Print in your browser. You should have at least one option to Print to PDF, and if using Chrome you can Save to PDF for printing, too.

      Good luck.

    • David
      September 11, 2016 at 4:55 pm

      If you're using Firefox, there is a "book" icon in the address bar for a reading view. It strips everything but the article making a clean print.

  11. Bruce Epper
    February 2, 2016 at 7:40 am

    Just a few items here:

    1. The '@' symbol on the @echo off line prevents the 'echo off' command from being echoed to the screen since the setting defaults to 'on'. It can be used in this manner for any particular command and it is not an integral part of the echo command.

    2. In the backup script, the 'set drive=X:Backup' line may produce unexpected results. I know that the pre/code blocks are stripping backslashes, but the paragraph after the code displays that line in the same manner. If the current directory on drive X: is not the root, your Backup folder may not appear where you want or expect it. If the batch file itself resides on the same drive and it is not executed from the root of the drive, the destination definitely will not be in the root. Users are better served using an absolute path rather than a relative path.

    3. ROBOCOPY didn't replace anything. Starting with Windows Vista it has become an integral part of the operating system. Prior to that, it was available only through the Windows [insert version] Resource Kits.

    • Gavin Phillips
      February 15, 2016 at 2:40 pm

      Cheers Bruce, all absolutely right. I've even accidentally a word in the ROBOCOPY explanation.

  12. Hadrian
    February 1, 2016 at 3:03 pm

    What is this? Windows 95?! Go with PowerShell instead!! Fewer commands, commands that make sense and follow similar structure, more flexible, easier to learn.

    • likefun butnot
      February 1, 2016 at 3:26 pm


      Both DOS-style batch programming and Powershell have their place. DOS-style more or less means that if you can conceive of the command line routine for doing something, you already know how to to write the batch file for it. It's great for trivial tasks like most of what is presented in this article.

      Powershell makes a lot of sense for someone with more of a programming background, but it also means spending a while looking at the command reference for whatever you're automating. No one has 30+ years of experience writing Powershell. Powershell command execution can also be slow and relatively CPU intensive, which might not be ideal for some situations.

    • nolongerapple
      February 1, 2016 at 10:18 pm

      I like batch. Much easier for simple things.

    • Gavin Phillips
      February 15, 2016 at 2:37 pm

      Hey Hadrian,

      As likefun butnot succinctly illustrated, both have their place, and we are duty bound at MUO to cover all the bases. However, a PowerShell article is on the way, so keep an eye out for that.


Leave a Reply

Your email address will not be published. Required fields are marked *