HOME
TOPICS
SEARCH
ABOUT ME
MAIL

 
Windows tips: A simple DOS batch file can be used with modern versions of Windows to make your own launcher for programs. Here's how to do it.
  technofile
Al Fasoldt's reviews and commentaries, continuously available online since 1983

Make your own launcher for startup programs


By Al Fasoldt
Copyright © 1998, Al Fasoldt


    The Windows Startup folder is a handy way to launch programs every time Windows starts up. That's why it's called the Startup folder, silly.
   But you knew that already. What you may not know is that you can create a better Startup launcher in a couple of minutes. Your homemade launcher will do two things that the one in the Start Menu can't do. It will let you choose which programs are started first, and it will give you a simple way of cushioning the launch of any programs by inserting delays between certain ones.
   Some background first. Windows looks at many different locations for information on what programs it should launch when it starts up. Some of that information is stored in the Registry, and some is stored in the WIN.INI file in the Windows folder. (There are other places, too, but we'll skip that part of the discussion.) You can spot the entries in WIN.INI easily: They're in RUN= and LOAD= lines. No harm is caused if you leave them there, but the problem with running programs at startup from those two lines is that you're likely to forget that they're there. When programs are listed in the Startup folder or in your own launcher, you can't ignore them.
   As for the startup programs in the Registry, use Regedit to find "runonce," then back up one folder when the first "runonce" entry is found. You'll see a "run" key. That's the Registry key where programs are launched at startup. These are launched before the ones in the Startup folder or in your launcher.
   The idea behind this Registry key is to let Windows run background programs that the user can't mess with. That's the idea, but the execution is left to every software writer and his mother's uncle. Many programs stick themselves into this key when they should have put entries in the Startup folder instead. So take a look at the "run" key and see what you find. Leave obvious background programs alone (anti-virus software and that kind of thing), but feel free to move normal programs out to the Startup folder or your own launcher. And feel just as free to delete stuff that was supposed to have been deleted in a previous Uninstall operation.
   (The Registry is nothing to fool with, so don't take my comments as liberty to experiment with any part of the Registry. Make sure you have a backup of the Registry before you do anything else. See "Backing up the Registry" elsewhere in this book.)
   Now to the good part. Open the Startup folder. An easy way to get to it is by right clicking the Start button and choosing Open. Double click Programs, then Startup. Leave the Startup folder on your screen, off to the side. Create a new text file in Notepad or your favorite replacement for Notepad. (If you're actually using Notepad and not one of the excellent replacements, you need a nudge: GET A REPLACEMENT FOR NOTEPAD. Good ones are free.) You'll be making a batch file with the text editor.
   Start the new text this way:
   @echo off

   That's a batch-file command. Use it at the top of all batch files. (It tells the computer to stop showing every command as it's being read in the batch file.)
   Now go back to the Startup folder and right click on the first icon. Choose Properties, then Shortcut. You'll see that the "Target" line is highlighted. Press Ctrl-C. That copies the highlighted part to the clipboard.
   Go to the text window. Put your text cursor at the beginning of the line below "@echo off" and press Ctrl-V. That pastes the line you copied from the Shortcut window. Back up to the beginning of the line and type "start" in front of everything. Here's a sample:
   @echo off
   start c:\windows\myprog.exe

   Now do the same thing for any other icons in the Startup folder. Put each on a line by itself in the text. (You're not through yet, but get this part of the job done before you tweak the file.) Then look at each line and find ones that have spaces in the pathnames of the programs. (A pathname is the combination of the location plus the executable file. Before Windows 95, you couldn't have real spaces in pathnames, but these days spaces are common.) Each pathname that has spaces needs to be set up in double quotes. Here is an example:
   start "C:\Program Files\CPU Monitor\CPUmon.exe"

   Now look at each line that does not have quotes setting it off and look for pathnames that have portions with more than eight characters between the backslashes or portions that use such formerly "illegal" characters as periods. Surround those with double quotes, too. Here are two examples of that kind of entry:
   start "C:\Downloads\ZipManager\ZipMan.exe"
   start "C:\My.Kid.Named.This.Folder\Calenders\Monthly\ReportCard.exe"

   Save the text file using the name STARTUP.BAT. Make sure your text editor doesn't fool you behind your back and create "STARTUP.BAT.TXT" instead. (If it does, try again and put the name in quotes, like this: "STARTUP.BAT" right in the entry line of the Save As window.)
   Create a folder in the Start Menu (not in the Startup folder!) called Startoff. Select all the icons in the Startup folder, hold down the Shift key, and drag them into the Startoff folder. (This makes sure they are moved and not just copied.) Locate the batch file you just created and click on its icon once. Then press the right mouse button and drag it to the Startup folder. Let go and choose Create Shortcut(s) Here. That puts a shortcut to STARTUP.BAT in the Startup folder.
   Right click on the icon you've just created in the Startup folder and choose Properties. Click the Program tab. In the Run: line, choose Minimized, and click the Close on exit box.
   Open the Start Menu, choose Shut Down, choose Restart the computer?, hold down the Shift key and click Yes. This restarts Windows without rebooting the PC.
   See if the programs you typed into the batch file run OK. If any do not, reopen the batch file and check the syntax (the way pathnames are listed). When in doubt about whether a particular pathname should have quotes around it, just put in the quotation marks. (Windows doesn't care if a pathname that does not need quotes has them nonetheless.)
   Now it's time to fine-tune your Startup file.
   Change the order of execution so that the programs that are the smallest (or the ones that do the least, using your own judgment) are at the top, and the ones that are heavy-duty (an e-mail program, for example) are at the bottom.
   Try it out again. See if the programs start up any faster this way. Feel free to play with the order of execution, keeping in mind that Windows will go to the next few programs while a previous one is still loading. (They usually don't load one at a time -- but they can, using a trick I'll tell you about next.)
   For ultimate control over your Startup programs, you can insert a delay at any point in the execution. You get delays using CHOICE, a program included with Windows. CHOICE apparently wasn't designed to do that we're going to do with it here, so the method is a little tricky. Pay close attention.
   CHOICE goes on a line of its own in front of any start command that you want to delay. The basic syntax goes like this:
   choice /c:ÿ /t:ÿ,5 /n

   The odd character following both the "c:" and the "t:" is produced on your keyboard using a real text editor. The character is seen by Windows as a space, but it's not a real space. It's the last character in the standard set of characters (called the ASCII set) and is usually considered a non-printing character.
   Windows lets you type any character, whether it's on your keyboard or not, using the Alt key and the keypad number keys. You hold down the Alt key and press four digits, always starting with zero -- press four, not three digits! -- to get the character to appear. For example, to get an "X" to appear on the screen, you'd type 0088 on the keypad while holding down the Alt key. Characters with low numbers are usually translated before they get to the screen because they are "control" characters, and characters with high numbers (0255 is the top) are always odd-looking to English-speaking people.
   (This won't work in Notepad. Did I tell you already to ditch Notepad? It will work in WordPad, but heed this solemnly and carefully: If you use WordPad to edit batch files, make sure you save the batch file as text and be careful that WordPad does not put ".txt" at the end of the filename. And make sure word wrap is turned off. Did I already tell you to get a real replacement for Notepad?)
   Here's how you do it. Type this exactly, substituting my instructions for the characters in brackets:
   choice /c:[Alt-0255] /t:[Alt-0255],5 /n

   What this CHOICE instruction means is simple: Windows is told to run CHOICE, which delays everything for five seconds before letting Windows go to the next line in the batch file. To make the delay longer or shorter, change the number. A delay of five seconds should be plenty to give a big program a chance to load without interference.
   Here's how part of the batch file would look using CHOICE to delay execution:
   start "C:\Downloads\ZipManager\ZipMan.exe"
   choice /c:ÿ /t:ÿ,5 /n
   start "C:\My.Kid.Named.This.Folder\Calenders\Monthly\ReportCard.exe"

   Finally, I have one more trick. If you have a program that needs to get all of its work finished before anything else can happen, you can modify the START command using its wait switch. (A switch is an instruction that changes the way a command or program works.) It looks like this:
   start /w c:\folder\filename.exe

   Don't get carried away by this feature. You could, if you wished, write a batch file that ran your e-mail program and waited until the e-mail program was finished (and had exited) before running the next program in the list. But using the wait switch in the Startup file is risky; try it out if you have a program that needs wait until the previous program has exited before it runs, but otherwise just keep it in the back of your mind as a way of controlling non-startup files.