Sample Code

Launching Commands At Startup

If you are like me and you prefer to have all of the programs that you typically use under Windows NT/2000, arrayed across the menu bar at the bottom of the screen, in a particular order, so that you can always click on the right program without thinking, this sample code will show you how to get this to happen at startup.

Under Windows NT/2000, you can add shortcuts to any programs, that you want to launch, to the startup directory. However, the order in which program icons appear on the menu bar at the bottom of the screen depends on the order in which the programs' windows are created. Even if you can get Windows to run the programs in the right order at startup (although there's not any guarantee of this), you can't be sure that the window creation order will be what you want. Essentially, placing shortcuts in the startup directory is a random thing. The order in which the corresponding programs will be started is not certain.

Launching Commands Under Program Control

The way to achieve the desired outcome is to create a command file (what used to be called a batch file) that determines the order in which the commands are started. In this file, delays can be inserted to allow slower programs to create their windows before the next program is launched, thereby ensuring the correct ordering of the program icons on the menu bar.

Programs that create their own window and detach themselves from the process that initiated them can be run directly from the command file. Those that skip either of these steps can be run under the "start" command, which creates a new window and does not wait for the executed command to end. The "/min" option of the "start" command can be used to run commands with their window initially minimized.

The sequencing of commands so that their windows come up in the desired order (so that their icons appear on the tool bar in the desired order) can be accomplished by judiciously inserting sleep commands into the command file to allow the slower commands to start up properly before the next one is run. If you do not have "sleep.exe" from the Windows Resource Kit, you can download doze.exe, which works the same way. This kind of program, rather than a batch file that uses a busy wait, should be employed for sleeping to allow the command that is starting up to have a shot at the CPU resources.

Under Windows NT, you can open up a box with a grouping of command shortcuts simply by using the "/d" option of the "start" command and pointing it to the directory where the shortcuts are kept. For example:


start /d """c:\Profiles\Everyday Items"""

The same effect can be achieved under Windows 2000 by starting the directory where the shortcuts are kept itself. Instead of using the "/d" option of the start command, the name of the directory is given after a title (note that the title must be specified or Windows 2000 opens a command window with the directory named as its title). For example:


start "Everyday Items" "c:\Profiles\Everyday Items"

Either of these approaches can allow you to provide a second-level link to a set of less-frequently used commands (the first level is on the screen menu bar). It will also allow you to launch the Control Panel under Windows 2000 in a new window, instead of causing the existing window to be taken over.

It is also possible to launch a command processor window with an intelligent number of rows/columns and a history buffer of reasonable size, despite the fact that you cannot assign properties to commands as you start them. To accomplish this feat, you need to do a little Registry hacking. Hack the "HKEY_CURRENT_USER/Console" Registry key and set the "HistoryBufferSize" to 0xC8, "ScreenBufferSize" to 0x1F40050 and "WindowSize" to 0x370050. This will cause the command window to be launched with a screen size of 55x80, a scroll back buffer of 500x80 and a history buffer of 200. Other values may be used. Just bear in mind that they are hexadecimal and that the rows x columns are expressed as a single number with the rows in the top two bytes and the columns in the bottom two.

Any command can be made to run in a particular startup directory by changing the drive letter and/or changing the directory before it is launched.

Sample Windows NT Command Launcher

Here is a sample command launcher for Windows NT that fires up all of the commands that I like to use, in the correct order. This single command file has a shortcut to it placed in the startup directory for the user. The "doze.exe" program is employed for sleeping. Note that quoted file names must use triple quotes.


rem
rem Command file to launch task bar items at startup.
rem
rem Commands are launched in order so as to fill up the task
rem bar from left to right.
rem

rem
rem The task manager system performance monitor.
rem
start /min c:\winnt\system32\taskmgr.exe
c:\utils\Doze.exe 2
rem
rem A box with shortcuts to everyday items.  "Everyday Items" is
rem really a directory with shortcuts to a bunch o' commands.
rem
start /d """c:\Profiles\Everyday Items"""
c:\utils\Doze.exe 2
rem
rem A command window.
rem
rem To get the command window to come up with the right
rem properties, hack the HKEY_CURRENT_USER/Console Registry
rem key and set the HistoryBufferSize to 0xC8, ScreenBufferSize
rem to 0x1F40050 and WindowSize to 0x370050.
rem
d:
start "Command Prompt" /min cd d:\website
c:
c:\utils\Doze.exe 2
rem
rem Windows explorer (none of this "My computer" crap-oh-la).
rem
c:\winnt\explorer.exe
c:\utils\Doze.exe 2
rem
rem Mr. Text Editor.
rem
cd c:\epsilon\bin
start c:\epsilon\bin\e32.exe -w7
cd \
c:\utils\Doze.exe 5
rem
rem A few (or six) telnet windows.
rem
start /min d:\crt\crt.exe /S MrServer
c:\utils\Doze.exe 4
start /min d:\crt\crt.exe /S MrServer
c:\utils\Doze.exe 4
start /min d:\crt\crt.exe /S MrServer
c:\utils\Doze.exe 4
start /min d:\crt\crt.exe /S MrServer
c:\utils\Doze.exe 4
start /min d:\crt\crt.exe
c:\utils\Doze.exe 4
start /min d:\crt\crt.exe
c:\utils\Doze.exe 4
rem
rem Adobe stuff.
rem
start /min d:\Acrobat\Reader\AcroRd32.exe
c:\utils\Doze.exe 10
start /min d:\PhotoShop\Photoshp.exe
c:\utils\Doze.exe 10
rem
rem Editors (various and sundry).
rem
start /min d:\Office\Office\winword.exe
c:\utils\Doze.exe 2
start /min d:\HexEdit\hworks32.exe
c:\utils\Doze.exe 2
rem
rem Email.
rem
start /min d:\Eudora\Eudora.exe
c:\utils\Doze.exe 10
rem
rem Browser.
rem
start /min d:\Mozilla\Netscp.exe
c:\utils\Doze.exe 10
rem
rem SanDisk SmartMedia swapper.
rem
d:
cd d:\sandisk
d:\SanDisk\safeswap.exe
cd d:\
c:

Sample Windows 2000 Command Launcher

Here is a sample command launcher for Windows 2000 that fires up all of the commands that I like to use, in the correct order. This single command file has a shortcut to it placed in the startup directory for the user. The "doze.exe" program is employed for sleeping. Note that titles must be supplied to any commands that use "start", under Windows 2000, or the command may not be launched properly (e.g. instead of the Task Manager coming up minimized, it will be launched in a maximized window titled "/min"). There is no harm in specifying a title in all cases.


rem
rem Command file to launch task bar items at startup.
rem
rem Commands are launched in order so as to fill up the task
rem bar from left to right.
rem

rem
rem The task manager system performance monitor.
rem
start "Task Manager" /min c:\winnt\system32\taskmgr.exe
c:\utils\Doze.exe 2
rem
rem A box with shortcuts to everyday items.  "Everyday Items" is
rem really a directory with shortcuts to a bunch o' commands.
rem
start "Everyday Items" "c:\Profiles\Everyday Items"
c:\utils\Doze.exe 10
rem
rem A command window.
rem
rem To get the command window to come up with the right properties,
rem hack the HKEY_CURRENT_USER/Console Registry key and set the
rem HistoryBufferSize to 0xC8, ScreenBufferSize to 0x1F40050 and
rem WindowSize to 0x370050.
rem
d:
start "Command Prompt" /min cd d:\website
c:
c:\utils\Doze.exe 2
rem
rem Windows explorer (none of this "My computer" crap-oh-la).
rem
start "Explorer" /min c:\winnt\explorer.exe
c:\utils\Doze.exe 2
rem
rem Mr. Text Editor.
rem
start "Epsilon" "c:\Program Files\Epsilon12\bin\Epsilon.exe"
c:\utils\Doze.exe 10
rem
rem A few (or six) telnet windows.
rem
start "MrServer" /min "c:\Program Files\crt\crt.exe" /S MrServer
c:\utils\Doze.exe 4
start "MrServer" /min "c:\Program Files\crt\crt.exe" /S MrServer
c:\utils\Doze.exe 4
start "MrServer" /min "c:\Program Files\crt\crt.exe" /S MrServer
c:\utils\Doze.exe 4
start "MrServer" /min "c:\Program Files\crt\crt.exe" /S MrServer
c:\utils\Doze.exe 4
start "Prompt" /min "c:\Program Files\crt\crt.exe"
c:\utils\Doze.exe 4
start "Prompt" /min "c:\Program Files\crt\crt.exe"
c:\utils\Doze.exe 4
rem
rem Adobe stuff.
rem
start "Acrobat" /min "c:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe"
c:\utils\Doze.exe 30
start "Photoshop" /min "c:\Program Files\Adobe\Photoshop 5.0\Photoshp.exe"
c:\utils\Doze.exe 10
rem
rem Editors (various and sundry).
rem
start "Word" /min "c:\Program Files\Microsoft Office\Office10\winword.exe"
c:\utils\Doze.exe 5
start "Hex Workshop" /min
    "c:\Program Files\BreakPoint Software\Hex Workshop 3.0\hworks32.exe"
c:\utils\Doze.exe 2
rem
rem Email.
rem
start "Eudora" /min c:\Eudora\Eudora.exe
c:\utils\Doze.exe 10
rem
rem Browser.
rem
start "Mozilla" /min "c:\Program Files\mozilla.org\Mozilla\mozilla.exe"
c:\utils\Doze.exe 10