Microsoft

Build Your Skills: Getting control of your computer's startup

Use this startup control system, built on batch files, to determine what loads and when.


I admit it—I’m something of a Luddite. New technology doesn’t necessarily always mean better. I miss being able to control what loads at each startup, and I resent programs that add themselves to my startup queue without asking, especially when I can’t figure out how to keep them from loading. I’m just enough of a control freak that I have always wanted to be in charge of my computer, not the other way around. When it came to controlling what loaded and when, though, it seemed I was just going to have to live with it.

Until last year.

That’s when I read an article that explained the various places that startup commands are stored. The article also referenced a utility (StartEd, by Thomas Reimann) that let you check or uncheck various startup programs, then save the changes for the next time you rebooted. “That’s cool,” I thought, “but I want dynamic control each time I boot, rather than getting into Windows, making the changes, and rebooting. And, I want a quick way to load everything or load nothing, as well as a default setting so I can walk away from it. How can I do all that?”

It took some research on my own, and a bunch of trial and error, but I finally came up with just such a system. It’s not high tech—it’s built on batch files, for gosh sakes—but it does the job, and does it both effectively and efficiently. And after all, isn’t that what software is supposed to be about?

I got a new laptop late last year, and I didn’t put my Startup Control System (SCS) on it at first. Recently, though, I decided the startup sequence was once again out of control, so I chugged through putting it on this box. As I was doing it, the thought occurred to me that some of you might enjoy such a system yourself. So, read on, and you can benefit from my trial and error.
"Luddite” is a term that refers to British workers who in the early 1800s rioted and destroyed textile machinery in the belief that such machinery would diminish employment. So a Luddite is anyone who opposes technical or technological change. The term is named after Ned Ludd, an English laborer who was supposed to have destroyed weaving machinery around 1779. (Source: Dictionary.com and The American Heritage Dictionary of the English Language, Third Edition)
Where Windows puts startup commands
The first thing you need to understand is all the different places Windows stores your startup commands. There are six places in the Registry, two in WIN.INI, and the StartUp Folder itself inside the Windows folder. Also, there are your AUTOEXEC.BAT and WINSTART.BAT files, which fire off when your computer starts and when Windows starts, respectively. See Table A for a complete list.

Table A
Use this table to figure out what’s happening when you start your system.


In the Registry
Once you find the Registry entries, they are pretty easy to understand. Basically, anything labeled as RunOnce is run one time and then deleted. This would include such items as the second part of an install program that has to reboot the machine. We don’t care about these, since they need to run the one time and then go away.

The Services programs need to load before the Desktop appears. Typical uses for this would include virus checkers and system-level utilities, such as Norton Protection for the Recycle bin. These programs load while the Log In dialog box is waiting on you to enter your password and log in to Windows.

The straight Run programs load after the Desktop appears. These would include most of the programs that simply need to run after Windows has started.

The CurrentUser keys are, obviously, for multiuser systems. I didn’t have to deal with this on my machine, so if you do, you’ll have to give some thought to adapting the process I outline to a multiuser box.

Outside the Registry
The Start-Up folder is the equivalent of the Run sections in the Registry, except that the end user can modify it simply by creating or deleting links in the folder itself.

The Load= and Run= line in WIN.INI are the predecessors to the current sections in the Registry and the Startup folder. They still work, though, and some programs still stick entries there.

Your AUTOEXEC.BAT file runs when you start your computer. The WINSTART.BAT file runs right before Windows switches from character mode to graphical mode.

The solution
Basically, what we want is something that asks us at each bootup what startup programs we want to run. Based on our input, the programs will then either run or not.

What we’re going to do is ask the questions in the AUTOEXEC file, and then set environmental variables based on the answers. Then, in each of the Run sections of the Registry, we’re going to delete the keys that automatically run the startup programs, and instead call a batch file—one batch file for LocalRunServices, and one for LocalRun. Inside each batch file, we’ll check to see if the environmental variable was set, and if it was, we’ll run the program.

It would be nice if we could put the startup questions in the WINSTART batch file, so they wouldn’t run if we weren’t actually going to progress to the graphical interface. Unfortunately, we have to set the variables in AUTOEXEC; the WINSTART file starts its own shell session, so the variables go out of scope once it exits. The ones set in AUTOEXEC, on the other hand, are still around even after the Desktop appears.

So, here’s what you do:
  • If you are at all unsure about editing the Registry, don’t do this at all.
  • If you are okay with editing the Registry, then start by making a backup of it. (If you don’t know how to do that, go learn how and then come back.)
  • Create two batch files in the Windows directory. Call one LOCRUNS.BAT for LocalRunServices, and the other LOCRUN.BAT for LocalRun. Inside each batch file put the following, adjusting the text according to which file it is:
@echo off
REM=====LocRunS.bat
REM=====This batch file is used for startup commands in the
REM LocalRunServices section of the Registry.

ECHO This is LocRunS.bat.

PAUSE

Next, add a Registry entry for each file. LOCRUNS.BAT should be called from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices, and LOCRUN.BAT should be called from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.
  • Reboot and test. If you have gotten this far correctly, a DOS window should pop up at the login prompt, stating it is LOCRUNS.BAT, and a second DOS window should pop up once the Desktop appears, stating it is LOCRUN.BAT. Note that you will have to hit a key to make each window finish, and then you will have to close them manually. We’ll deal with that later.
  • Make a list of all the startup commands on your system and what programs they call. Be sure to include any parameters required. You can do this by examining the Registry directly, or by using StartEd. Double check to be sure you got everything exactly right; no room for slipups here.
  • Decide which of these programs you want to ask about, and which ones you’ll let run every time. I let the SysTray run without interference, since it is necessary to the operation of Windows. And, I let Norton Image run unmolested, since it does its thing and exits.
  • Also, be sure to note any programs that come in two parts. You’ll ask about the program only once, but you’ll have to add commands for it in both batch files.

Including questions
The next step is to add the necessary questions to your AUTOEXEC.BAT file. I’ve included mine in Listings A, B, and C so you can see how to use the CHOICE command. Basically, you ask the question, and then set the environmental variable based on the response. If you want to check your work, you can add SET and PAUSE under the questions, so you can see which variables are actually getting set, and to what values.

If you want to double-check your work to this point, modify the two batch files by adding SET on a line by itself before the PAUSE. That way, when each one comes up, you can make sure the variables are getting set properly and are still seen by the batch files. If they don’t show up, or don’t have the right values, stop and debug it until it works. Remember, if the variables don’t get passed correctly, nothing else will work.
Regarding the three batch files I use for my SCS—my AUTOEXEC and the two other files: Note that I use 4DOS, which is a replacement for COMMAND.COM that I’ve been using for years. (I highly recommend it.) The special CLS command that sets colors, the DRAWBOX command, the SCRPUT command, and the SCREEN command are all 4DOS-specific. I did go ahead and use CHOICE, though, which is a standard command in the Windows/Command directory. For help on the CHOICE, simply go to a command prompt and type CHOICE /?. @echo off

REM=====General settings.

set temp=C:\temp
set tmp=C:\temp
set path=C:\windows;C:\windows\command;D:\progra~1\norton~1\norton~1;c:\4dos

REM=====Clear variables if they already exist. No reason to, but let’s be safe.

set navstart=
set nav=
set nprotect=
set symtray=
set cleansweep=
set spdstart=
set quickres=
set dialoghelp=
set toolbar=
set quickshelf=

REM=====Set up the screen.

cls bri whi on blu
drawbox 0 0 4 79 4 bri red on blu
scrput 2 33 bri yel on blu Startup Menu
screen 6 0

REM=====Choices

choice /t:n,10 Do you want to skip everything
if errorlevel==1 goto End

choice /t:y,10 Do you want to load everything

if errorlevel==2 goto AskEach

set nav=y

set nprotect=y
set symtray=y
set cleansweep=y
set spdstart=y
set quickres=y
set dialoghelp=y
set toolbar=y
set quickshelf=y

Echo.

Echo Running NAV Startup
@D:\PROGRA~1\NORTON~1\NORTON~2\NAVDX.EXE /Startup
quit

:AskEach

choice /t:n,10 Do you want to run the NAV Startup
if errorlevel==1 set NavStart=y
if errorlevel==2 set NavStart=n
choice /t:n,10 Do you want to run the NAV Auto-Protect
if errorlevel==1 set nav=y
choice /t:n,10 Do you want to run the Nprotect
if errorlevel==1 set nprotect=y
choice /t:n,10 Do you want to run Symtray
if errorlevel==1 set symtray=y
choice /t:n,10 Do you want to run Cleansweep
if errorlevel==1 set cleansweep=y
choice /t:n,10 Do you want to run SpeedStart
if errorlevel==1 set spdstart=y
choice /t:n,10 Do you want to run QuickRes
if errorlevel==1 set quickres=y
choice /t:n,10 Do you want to run Dialog Helper
if errorlevel==1 set dialoghelp=y
choice /t:n,10 Do you want to run the Toolbar
if errorlevel==1 set toolbar=y
choice /t:n,10 Do you want to run QuickShelf
if errorlevel==1 set quickshelf=y

if %NavStart==n quit

Echo.
Echo Running NAV Startup
@D:\PROGRA~1\NORTON~1\NORTON~2\NAVDX.EXE /Startup

:End

REM=====LocRunS.bat
REM Used to run programs in the Local Run Services section.

@echo off

cls
if %nprotect==y "D:\Program Files\Norton SystemWorks\Norton Utilities\NPROTECT.EXE"

if %cleansweep==y D:\PROGRA~1\NORTON~1\NORTON~3\CSINJECT.EXE


if %symtray==y "D:\Program Files\Common Files\Symantec Shared\SymTray.exe" "Norton SystemWorks"

REM=====LocRun.bat
REM Used to run things in Local Run or Startup Folder.

@echo off

cls

if %nav==y D:\PROGRA~1\NORTON~1\NORTON~2\NAVAPW32.EXE /LOADQUIET


if %nprotect==y "D:\Program Files\Norton SystemWorks\Norton Utilities\NPROTECT.EXE"


if %cleansweep==y "D:\Program Files\Norton SystemWorks\Norton CleanSweep\csinsm32.exe"


if %spdstart==y "D:\Program Files\Norton SystemWorks\Norton Utilities\NSS\SPDSTART.EXE" /Autostart


if %quickres==y C:\WINDOWS\QUICKRES.EXE


if %dialoghelp==y C:\Utils\PDesk\pddlghlp.exe


if %toolbar==y C:\Utils\PDesk\Pdesk.exe


if %quickshelf==y "D:\Program Files\Microsoft Reference\Bookshelf 2000\qshelf2k.exe"




Taking the plunge
Now you’re ready for the fun part. You can take it one program at a time, to make sure you’ve got it right, or do them all at once. (If you are the least bit unsure of this process, or aren’t sure you understand what’s going on, do some minor program first.)

Pick one of the startup commands and delete it from the Registry. Then, based on which section of the Registry it came from, add it to the appropriate batch file. Put the “IF %variable==Y” test in front of the command line, so that you wind up with something like this:
if %toolbar==y C:\Utils\PDesk\Pdesk.exe

(Be sure to remember the double equal sign.)
  1. Reboot and test. If you have “done good” to this point, you should get the question, answer it, and the program should run or not based on the choice you make. You’re still running the SET command, so you should be able to tell whether or not the variable is being set properly.
  2. Do the remaining commands. Be sure to check each program to make sure it is loading properly.
  3. At this point, you’ve got the system going. The programs you want to control are only loading when you tell them to in the AUTOEXEC file, and your Registry has an entry in the LocalRunServices section that calls LOCRUNS.BAT, and an entry in the LocalRun section that calls LOCRUN.BAT. Assuming everything is working, you can clean up the two batch files by removing the ECHO, SET, and PAUSE lines, so that the batch files run without help from you.
  4. The last step is to modify the batch files to make them as unobtrusive as possible. Go to your Windows directory, right click on each file, and choose Properties. In the Properties dialog, go to the Program tab and choose Minimized for the window state and check the “Close on exit” option. You’ll still see the batch files as they go by, but they will be a quick flash in the taskbar and then gone.

That’s it! Even though it pops up in a character-based screen, you’ve got control of your startup routine once again. Now if I could only do the same thing to take care of all the networks I log in to. 16-bit Novell, anyone?

Bruce Maples is an author, trainer, speaker, and consultant living in Louisville, KY.

To comment on these tips, please post a comment below or drop us a note.

Editor's Picks

Free Newsletters, In your Inbox