Pinterest Stumbleupon Whatsapp
Advertisement

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, but powerful Windows tool. We'll show you the most useful commands every Windows user needs to know. Read More .

Advertisement

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
exit

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
pause

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!
@pause

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.

Static

You should type the following for your static batch file:

netsh interface ip set address "LAN" static "xxx.xxx.xxx.xxx" "xxx.xxx.xxx.x" "xxx.xxx.xxx.x"

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.

Dynamic

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
:W
If %time%==23:30:00.00 goto :X
: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!

Leave a Reply

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