How-to: Use batch files to create a working environment

Difficulty: 3

Batch

Have you ever noticed that when you get started on a particular task on your computer, you always open up the same bundle of programs to do it? Why not make it easier for yourself and get all of these programs loading up when you want them, with a single click. The answer is batch files.

Batch files have been around longer than Windows has, but sadly they have been forgotten over the years. Generally, DOS is not a nice environment to work in compared to the graphical operating systems we have these days. I feel batch files still have their place. They are very simple to create and they can be edited easily.

You may have already set up your computer to automatically launch particular programs as part of your computers start up sequence. While this will work, it is not really the ideal situation, because you may not be ready to use the programs straight away. This can slightly slow you down or clutter your workspace, for no good reason. Instead, if you use batch files, your specified programs will launch simultaneously with one click, only when you’re ready to use them.

In this article we will look at how to create some basic batch files which you can alter to suit your own needs. For this How-to article, I am going to use batch files to launch environments, e.g. turning your computer into a multimedia heaven. 

When I first thought about this article, I was thinking of a particular scenario I suffer with. I am sure there are a number of similar scenarios where a batch file can help. Take note of excessive clicking and ask yourself if you could automate the clicks by creating your own batch file.

Batch files will help to free up the machines power to launch programs. Computers have the power to load up multiple programs in the same time it takes you to get through the start menu, and click on one of the programs you want. With batch files, you can be up and running within seconds instead of a few minutes.

If you like where this article is heading, create a folder somewhere on your computer to put your batch files into, as you will probably make a few of them. Batch files won’t allow for the icon to be changed, so we need to make shortcuts to them, and then you can change the icon of the shortcut.

Open up Notepad and click “Save As”. You can name the file anything you want, but ensure you change the view to “all files”, and put a .bat on end of the file, e.g. multimedia.bat 

A few examples of what a batch file can do:

Load up a Program

We can use a batch file to load up any application or utility we might need to do a set task.

The command line to open up Winamp from the command line is:

Start "" "C:\Program Files\Winamp\winamp.exe"

You can find the path of most programs by navigating through the start menu to the program you want, right click and select properties. In the dialog that opens up, you should find the path and executable you will need to enter into the batch file.

The hardest thing to remember is the placement of the speech marks.

Load up documents

We are not limited to launching only programs. We can extend batch files to open up documents. This could be useful in all sorts of scenarios. For some people, they work on a particular Excel spreadsheet each day or they want their time-sheet when they get into the office.

This can normally be done by navigating to the folder of the document and then launching the document itself. Windows will look after which program it should open up in as the batch file will use the same defaults that have been built into Windows. The code to do this is below.

Start "" "C:\Documents and Settings\Username\My Documents\document.doc"

This should work for most programs, but if it doesn’t work for you, you may need to launch the program followed by the filename and path. e.g. on a single line, with no text wrapping.

Start "" "C:\Program Files\Microsoft Office\Office12\winword.exe" C:\Documents and Settings.. etc

The first option is desirable as it is quicker.

Load up Websites

As well as launching programs and documents, we are able to launch our browser with a particular website. This could be handy if you want to load a TV guide from a website along with TV viewing software.

The command to make this happen is as below:

Start "" "C:\Program Files\Internet Explorer\iexplore.exe" http://www.inspectmygadget.com

Load up an Environment

We can bring together what we have learnt to make a batch file that will load up all the necessary applications and utilities we might need to perform a set task. You can use this to set up an excellent working environment.

If you want to launch multiple programs at once, repeat the above example for each program, document or website, e.g.

Start "" "C:\Program Files\Winamp\winamp.exe"
Start "" "C:\Program Files\TechSmith\SnagIt 8\SnagIt32.exe"
Start "" "C:\Program Files\Microsoft Office\Office12\winword.exe"

This batch file will launch Winamp, SnagIt and MS Word all at the same time.

Some other examples

As everyones needs are different, I don’t want the above examples to be used as “The right way”. Each person needs to examine what will work best for them. Below are some combinations of what is possible to help you come up with a solution that may be right for you.

Keep in mind that batch files are extremely easy to edit, so if it isn’t working for you one way, it is easy to add, remove or edit any line you have previously put into the batch file.

Web Designer – Notepad, Flash, Cold fusion etc
Blogger – SnagIt, BlogJet, Ideas Document and a music player
Gamer – Resolution changer, Game, controller software and volume utility 
Government worker – Solitaire, Hearts, Miniclip, YouTube

Some of these examples are more practical than others, but you get the drift.

A more complex example

The command to launch multiple programs one after another rather than simultaneously, is slightly different to the example above. We need to remove the “start” command so that they don’t launch all at once. This will stop each new line of the batch file loading up automatically. Instead, each step will need to be closed before the next command line can be executed.

When I send my computers video signal over to my TV, I need to drop the resolution, open up Windows Media Center, and when I am finished with Media Center, I need to set the resolution back to it’s original state. The navigation of menus and multiple clicks can instead be reduced to a single execution.

In this example, I am using a utility called ResChange to change my resolution. The utility is completely controlled by the command line, so it is ideal for batch files.

Below is the code I used to make it all happen.

C:\ResChange\reschange.exe -width=640 -height=480 -refresh=60
%SystemRoot%\ehome\ehshell.exe
C:\Reschange\reschange.exe -width=1280 -height=1024 -refresh=max

The first line drops the resolution to 640×480
The second line launches Windows Media Center
The third line changes the resolution back to my Windows default.

I could not use compatibility mode to do this because I also needed to change the refresh rate.

This sequential type of batch file is ideal for a task that requires multiple programs, one after the other; e.g. Ripping a CD, you might rip the music off the CD in one program, convert the file to MP3 in another and then finally edit the tags in a third program. A batch file like this can be used to automatically launch the next step in the process.

There are hundreds of little utilities that we can use to improve our computing experience. Using them around our main programs, means that we don’t need to go through the hassles of manually loading them up.

Extras:

When loading up an environment where you may occasionally want to load an additional program, you are able to add questions into the batch file. e.g. If you want to load up load up a web browser and email program every time, and sometimes word as well. You can make the batch file open up the web browser and email automatically, and then prompt you to say yes or no to opening up word.

While that sounds nice, it is not really very helpful as it is quicker to load up word with mouse clicks instead of the example shown above. I thought I should mention it in case you wanted to experiment with such features.

We want to use batch files to speed us up and not slow us down, so I won’t go into how you can do this here.

Problems:

Batch files are not very smart. They do what they are told and they are only really able to execute commands. If you want to use batch files to load up environments, take note that you cannot use batch files to unload environments. Each program will need to be manually closed down individually (or closed at shutdown).

This is only really an issue if you want to use this method to load up a range of different environments. If you have two environments that launch your web browser, you will end up with two browsers open. While this is not a big issue, it could become frustrating over time and is worth mentioning.

Conclusion:

I hope you have found this article helpful, and that you may have a use to bring batch files back from the dead. Batch files are not going to make your computing experience feel modern or high tech, but they have the potential to really speed up the loading of your applications. Please stick around and check out some other articles at Inspect My Gadget for more time-saving tips and tricks.




Related Posts

78 comments so far »
 

  1. AK said, on April 30, 2008 @ 12:12 am

    Dear Chris, thank you for your reply. I do not want to create a short cut on the desktop myself but rather I would like the batch file to do that for me.
    For example, just as you would normally install a program, a desktop icon is created for the user; likewise I would like my batch file to do that.
    Thank you.

  2. Chris Duckworth said, on May 1, 2008 @ 1:06 pm

    AK, that’s getting a little trickier. You can use VB scripts and other complex things to make it happen, but I found it a bit too complicated.
    Would this work… Keep the shortcut static, always pointing to the same file. Use the rename command in your batch file to rename the most current file to the file the shortcut is pointing to. As it renames a file, rename the old one back.
    Either method is not easy.

  3. Murphy said, on May 4, 2008 @ 8:11 pm

    @AK: For creating a shortcut try to use a nircmd command line tool (http://www.nirsoft.net/utils/nircmd.html). One of the parameter for this tool is “cmdshortcut” which will do what you want. :)

  4. jinkx said, on May 14, 2008 @ 1:13 am

    whell im kinda new at wrighting .bat files and i can do only simple things but i was wondering if anyone knows about any websights to help me learn beter

  5. AK said, on May 15, 2008 @ 8:42 pm

    Dear Murphy, Thank you so much for pointing me into the right direction. That command line tool, NIRCMD was very handy and I managed to do what I wanted.
    May the Lord shower his Mercy on all of us.

  6. jamez said, on June 12, 2008 @ 2:32 am

    my .cmd file reads as follows:
    @ECHO OFF
    ECHO STARTING IEXPLORE
    START “” “C:\Program Files\Internet Explorer\iexplore.exe” http://springfield.craigslist.org/search/mcy?query=&minAsk=400&maxAsk=2500&hasPic=1/
    however, the last url opens as http://springfield.craigslist.org/mcy/
    why won’t it open to the search filters that i specified?

  7. jamez said, on June 12, 2008 @ 2:52 am

    never mind. i figured this out.

  8. Adrian said, on June 30, 2008 @ 11:06 pm

    Hi guys,

    How can I open multiple URLs in multiple browser tabs (not windows) using batch file?

    It works in Firefox, just put the internet addresses side by side and they will open in different tabs within the same Firefox window; but it doesn’t seem to work with IE.

    Thx.

  9. Marius said, on July 5, 2008 @ 11:32 am

    Hi

    Great article. At least for me who’s a newbe.

    I only want to know if it’s posible to make a autorun-file so when i open a document with a batch-file inside, if i can make a autorun-file that runs when i open the document?

    I know it’s posible to make autorunfiles who run in cd’s. But what about the hardisk?

  10. Chris Duckworth said, on July 6, 2008 @ 3:30 pm

    Hi Marius, I am a bit confusd as to what you are asking. It is possible to call batch files from another batch file. There are programs like nirCMD that let you make shortcuts that will run multiple programs from a single shortcut. If you can explain what you would like to do more clearly, I can try to help more.

  11. Chris said, on July 10, 2008 @ 10:04 am

    I have a folder of 1000 files that I need to convert to another file type (.fla to .swf). I found a .exe that will do this one file at a time. I’m wondering if there is a batch file I can create that will open a program (FLA2SWF.exe) and run it for every file in a specified folder?

  12. gnetiv said, on July 17, 2008 @ 2:02 am

    Hello all

    I have a internal website that gives me access to a admin console. I can launch the site with a script but I need to be able to enter a password to get to it. The username always stays the same on the page. I’ve tried the suggestions here:
    set /p password=%password%

    but no luck.

    Thanks in advance

  13. sanjay said, on July 17, 2008 @ 3:10 am

    how i can open multpul website st a time

  14. Jos Grupping said, on August 18, 2008 @ 8:53 pm

    Hello fellows,

    I use a setup with DOSBox and a series of batch files for starting up old (DOS) versions of Microsoft Flight Simulator.

    Since a few weeks I have a nasty problem. All the sudden the batch files stoppen running: they just open in Notepad instead. That is at the menu-option “Open”. And I can’t find a place where I can change this association of the .bat extenson. If I remember correctly there also used to be the option “Open with …” but I ca’t find that anymore.

    I did find a work-around by creating a new user account and tried to start my batch file there. It does work, but then I have to re-create the whole background for this new user account, which I don’t intend to do.

    Can anyone tell me what might be the reason for this unwanted coupling and how i can restore the old situation? Help would be very much appreciated.

    Jos Grupping
    Overasselt
    The Netherlands

    webmaster of the Flight Simulator History website

  15. Chris Duckworth said, on August 18, 2008 @ 9:48 pm

    Hi Jos

    You have an interesting problem. I haven’t experienced it myself, but maybe changing the extension to cmd instead of bat may work? IT should work the same way, you are just taking away any links that the bat extension may have developed.

    I have a couple more ideas up my sleeve if this doesn’t work.

    Cheers
    Chris

  16. Jos Grupping said, on August 19, 2008 @ 1:13 am

    Hi Chris,

    Thanks for the prompt and GOOD reply. IT WORKS OK, hurray!

    So I can continue now, which is very good, but it would be even better if I would be able to break that association between batch files and Notepad.

    One more remark about that: normally in Explorer, if you click on a file with the right mouse button, you get a pop-up menu with the option “Open” and a bit lower the option “Open with”. With the latter option you are able to change the standard association.

    However, in the case of .bat files that second option is missing in the pop-up menu. Why??? Maybe this gives you an extra clue?

    Anyway, many thanks for your reply so far,

    Jos G.

  17. Chris Duckworth said, on August 19, 2008 @ 9:25 am

    Hi Jos

    It occured to me… can you make sure that file extensions are shown. This can be done from explorer > tools > folder options > view. Maybe the file is really called file.bat.txt. This may be creating the association with notepad. If file extensions aren’t shown, it will appear as file.bat. A good indicator is the icon of the file.

    The “open with” shouldn’t be shown for a bat file. Only open and edit. Windows sees a bat file as a program, rather than a document.

    To change what program opens a file extension, this is also done in folder options. Bat files and cmd files are not listed though.

    Hope this helps.
    Cheers
    Chris

  18. Jos Grupping said, on August 20, 2008 @ 3:58 am

    Hi Chris,

    Thanks again, but that’s not the case I have “Hide file extensions for known file types” not chequed. Please forgive me if that’s not the exactly correct term, because I use a Dutch Windows version and have to try to translate the terms. So file extensions are all shown and it’s not: file.bat.txt.

    BTW, the trick of changing .bat into .cmd works fully, so I can work in my normal user-account. Which makes things a lot easier. Thanks a millon. However it hurts me that normal .bat files still don’t work.

    As you mention, there is (or in my case there was) a list of all file extension associations.The problem is that I can’t find that list any more. Although, if .bat and .cmd are not shown, it won’t help me with the .bat problem!?

    Anyway I still would like to have accesss to that list, because a recent unintended installation of some odd audio/video player has hyjacked all my audio and video extensions.And finding them al to set back manually is virtually impossible. But where has the list gone? I remember vaguey a function under the main configuration screeen, but maybe that was under Windows XP?

    So the status is: thanks to your advise I can work again, be it a bit crippled. But I really would like to find the real solution.

    Cheers again,

    Jos G.

  19. Chris Duckworth said, on August 20, 2008 @ 12:42 pm

    Hi Jos, I am glad that changing the extension worked. I am very confused as to why the open with option isn’t available. I have no idea how to bring it back. Probably a registry hack. The How-to geek website is full of good registry hacks that may bring it back.
    To solve how your file associations are broken, I recently came across a program called Types which will help recreate those associations quickly. Check out this article for more information.
    I hope you get some value out of my reply 😐

  20. Ben said, on September 30, 2008 @ 5:09 am

    @Jos:

    Using the cmd shell, you can print the list of filetype associations in Windows.. simply open the command shell and type
    assoc > associations.txt

    This will output all filetype extensions to a text file, which you can open and browse. (The command’s output is too large to be viewed in the command shell)

    To view just the .bat, type
    assoc .bat

    My association for “assoc .bat” is
    .bat=batfile

    If that isn’t what yours returns, you can change it by entering
    assoc .bat=batfile

    Hope it helps!

  21. Chris Duckworth said, on September 30, 2008 @ 8:52 am

    Ben, there are some great tips in your comment. I never knew you could do that. Very useful. Cheers.

  22. Camn Ron said, on November 6, 2008 @ 11:04 am

    Hey Guys, I love this thread.
    Lets make it move faster.
    I love learning how to use batch files.
    I am pretty experienced in them. Can someone give me some Experienced Examples?
    in Vista
    @echo off net user administrator activate:yes
    anyways Be back everday to see who put something up for me and of course reply

  23. Justin said, on November 13, 2008 @ 8:09 pm

    Hi Camn

    Here is a challenge for you.
    I want to run an html file that ive created from system start up. The trick is when the file opens up, i want it to automatically open up in fullscreen. Could you help me?

  24. Chris Duckworth said, on November 14, 2008 @ 8:32 am

    Hi Justin, IE has a kiosk mode that will load the page in full screen.
    iexplore.exe -k http://www.inspectmygadget.com
    Alt-tab will let you close it down.
    You can create a shortcut in your startup menu. I hope this has been helpful.
    Cheers

  25. aqi said, on March 23, 2009 @ 3:48 pm

    hi, how do we invoke batch files from c++.?

  26. Chris Duckworth said, on March 25, 2009 @ 9:04 am

    Hi Aqi, it would be like launching a progrom from within C. Look up the Shellexecute command, or the system command. I don’t know C, so I am not shure of the code, but it is bound to be possible.

  27. MrCEO said, on April 16, 2010 @ 1:45 pm

    here’s a batch file. Name it the Martix.bat
    @echo off
    color 2
    :start
    echo %Random% %Random% %Random% %Random% %Random% %Random% %Random% %Random% %Random%
    goto start
    It does nothing that is worth it but it kills time and is fun

  28. Ricky Tan said, on January 9, 2011 @ 10:47 pm

    Is there a way to create a file that will open a saved EXTENDED DESKTOP SCHEME (HDTV) and then change my SOUND DEVICE to Hdmi? Dell Inspiron 1525/ Windows Vista


Leave a Comment
 

Name: (Required)

E-mail: (Required but will not be published)

Website:

Comment: