Powers of Zero
Every NTnetwork manager knows how to write simple Windows NT batch command procedures.Whether used to script user logons, to install site-customized software, or tobulk-configure NT workstations and servers, batch command procedures are thefamiliar bread-and-butter of network-based Windows NT management.
Likewise,many NT managers know how to use numeric environment variables to pass andprocess arguments within the NT batch procedures they write. For example, afile called SHUTDOWN.BAT can be invoked at the command line as follows:SHUTDOWN.BAT \\COMPUTERNAME 90. When referenced within this SHUTDOWN.BATprocedure, the environment variables %1% and %2% will contain the values --arguments -- passed on the command line, in this example"\\COMPUTERNAME" and "90" respectively. These numericvariables, in turn, might subsequently be passed as arguments to theSHUTDOWN.EXE procedure from the NT resource kit to cause the named Windows NTsystem to shut down in 90 seconds.
Numericvariables can be used within batch jobs to test the arguments passed to themfrom the command line, or from a higher-level .BAT procedure. The results ofthese tests, in turn, can be used to vary the procedure's behavior underdifferent circumstances -- perhaps to configure Internet Explorer settingsdifferently for users in various domain groups or to generate Exchange e-mailprofiles with similarly variable characteristics. OK, now tell us something wedon't know.
How aboutthis: Did you know all .BAT procedures accept a %0% numeric argument as well?When referenced in a batch procedure, %0% always contains the full path of theprocedure's filename. While this may not seem like much, a few variations on%0% can prove very useful indeed to Windows NT managers.
Forexample, the arcane reference %0\..\, as you may have seen in batch proceduresfrom Microsoft and other vendors, refers to the directory from which thecommand file was executed. To get a listing of the parent directory of a batchprocedure, try putting the command "DIR %0\..\" in it. To run aprogram such as SHUTDOWN.EXE from the procedure's parent directory, try usingthe reference "%0\..\shutdown.exe."
By usingthe zero-argument like this in your batch procedures, you can write complexcommand files that can be executed without modification from any directory onany drive or network share. Procedures coded to run from a CD-ROM, for example,will work properly regardless of the CD-ROM's drive letter. More importantly,the same procedure will work just as well when launched from a mapped networkdrive or Universal Naming Convention path. By referencing the associated filesthat your batch jobs need -- .EXE and .INI files, for example -- via %0%, youcan replicate directories throughout a network, confident that they'll work asyou coded them wherever they may end up.
Othervariations of %0% can be useful as well. For example, %0\..\SUBFOLDER, refersto files in the SUBFOLDER subdirectory of your procedure's parent directory. Ifyou use %0\..\..\, it will point up the path to your procedure's grandparentdirectory or drive. Would you like your procedure to delete itself when itruns? DEL %0% will do it. This is a handy way to code run-once procedures foryour users' "startup" program groups.
Watch outfor a few %0% quirks, though. If %0% ever refers to file or folder names thatcontain blanks, you'll need to enclose your reference to %0% in quotationmarks. If you find any utilities that don't accept %0% references as arguments,try using a COPY command to copy the utility and any files it might need toyour %TEMP% directory. Then run the utility from there with a %TEMP% referenceas an argument.
If youwrite batch procedures to manage your networked Windows NT systems, take sometime to experiment with %0%. Before long, you'll learn that this obscure littleNT feature packs a lot of power. --AlCini is a senior consultant with Computer Methods Corp. (Marlton, N.J.)specializing in systems and network integration. Contact him at firstname.lastname@example.org.