Canned Responses to Selected Batch FAQs
These are standard responses I post in reply to some of the most frequent FAQs in alt.msdos.batch and alt.mados.batch.nt. These responses are from my point of view and do not necessarily reflect the opinions or practices of others.
Canned response to the '=' in an environment variable value FAQ.
NT's CMD.EXE can manage this, but all the other MSDOS-like
operating environments treat the '=' as a delimiter and barf
with a syntax error. Most non-Microsoft command processors
are expected to work correctly.
However, it is usually known that the variable is in the form
name=value, and usually the name part is known, so unless the
string is generated by some other program, it is practical to
store only the value part in the environment, and reassemble
the string on the command line that uses it.
Sometimes it is necessary to store both the name and the value,
using two variables. The key is to insert the forbidden character
manually when writing the code that uses the string.
For example, if one has the string "foo=bar" and wishes to
preserve it, the string can be broken up and saved in pieces:
set first=foo
set second=bar
echo %first%=%second%
Keep in mind that it is rather difficult to pass the string
into a batch file, unless it is quoted. If it is quoted, it
will be difficult to split up; if it is not quoted, it will
appear as consecutive arguments, for example, if TEST.BAT is
invoked as
test foo=bar
then %1 will be foo and %2 will be bar.
Canned response to posted binaries
Posting binaries here is outof order. Binaries posted in newsgroups
are the primary method of placing new malicious software in
circulation.
Standard warning about binaries downloaded from newsgroups:
Rule 1: Don't download it
Rule 2: If you do download it, don't run it.
Rule3: If you are going to run it anyway, scan it with several
current virus scanners before running it.
Rule 4: When applying Rule 3, *back up* the system before
executing the program.
I am not saying your program is malicious, only that it is
indistinguishable from a malicious program until it is run, and
if it is malicious, by then it's too late.
Canned response to the file/directory name as date FAQ.
There are pure batch ways to do this, but they are operating
system and/or OS language specific (and these FAQs seldom indicate
the OS or language), and have severe restrictions on the available
functionality.
In an effort to answer these questions in an OS and language
independent way, I have published a set of Web pages dealing with
date and time issues using a free secondary language you can
download that doesn't care about the OS or the user's system language.
The pages are /batch/multilingual.html for
information on obtaining and dealing with the language and
/batch/awk.scripts.time1.html and
pages off it for general date and time issues. Please refer to
these pages for specific solutions and enough background material
to allow you to craft your own if the one you need isn't already
there.
Canned response to how do I get network user information FAQs.
Look in the environment - use the command
set > environ.txt
then open the file in a text editor.
If your network login script sets the username or other network
information you need, you will see a variable that has the
information.
In my case, the NT user name is given in USERNAME and the Netware
user name in NWUSERNAME, the Ethernet address in ETHERADDR, the
local computer name in COMPUTERNAME, etc. - your results will vary
with your network type and login script details.
In any case, if the variable exists, you refer to it in a batch file
as %variable% where "variable" is the name of the variable (the part
in front of the '='. When so referenced, the symbol is replaced with
the value of the variable.
It is possible to extract some information from the registry by
exporting the key, then processing the resulting file to extract
the data, but it is much easier and more convenient to put
commands to set environment variables in the login script. If
they are not there and you are not the administrator, suggest to
the administrator that putting them there would be a good idea.
Canned response to the how do I make a batch file run at a specific time or on a specific day FAQ.
Microsoft offers this advice for Win95 and NT:
"To Start Task Scheduler
If your computer runs Windows 95 or later, click Start, point to
Programs, point to Accessories, point to System Tools, and then click
Scheduled Tasks.
If your computer runs Windows NT, click Start, point to Programs,
point to Administrative Tools, and then click Scheduled Tasks."
None of this appears in any of my Win95 or NT systems. It appears
to be part of the Plus Pack, which I do not recommend installing.
If it's already there, and the machine still functions, give it a try.
Many third party packages come with schedulers: some anti-virus
programs, some network clients, some utility packages. Other
schedulers are available at the various archives for your operating
system.
NT has the AT command, which has some formatting issues that make it
hard to use, but the NT resource kit has a wrapper for it called
WinAT that is easy enough. Both require that the Scheduler system
service be started. When experimenting with AT and WinAT, it is a
good idea to make sure the program runs in Interactive mode so you
can see what's happening. I have not been able to make anything
related to networks work with AT: it doesn't want to run a program
off the network, connect to the network, read files off the network,
etc.
It is possible to write a scheduler in batch language, but the
performance penalty is severe - see
/batch/exmp1.htm#attime.
Canned response to the where can I get batch information of the Web FAQ.
There are many good batch related Web sites, but based on the number
of hits on my pages that come from Terry Newton's list of links, I'd
have to say that http://www.nc5.infi.net/~wtnewton/batch/index.html is
a very good place to start looking - nearly all the major sites
are listed there.
Canned response to the how do I do something to files that are 'n' days old, or older than some specific date
Usually these questions are asked without specifying the operating
system, a point that can make ther difference between the limited and
the extremely ugly. Often the question of days means something
other than sequential calendar days: business days, for example.
I have prepared a Web page addressing the entire range of
possibiliites at /batch/awk.scripts.time2.html - if your
question is not covered, let me know and I'll try to add it. The
approach taken is to use a free secondary language that has really
useful date and arithmetic functions to do the sophisticated date
calculations under the control and management of a batch program.
Background material on the date functions is at
/batch/awk.scripts.time1.html and general
background material, including access to the language used is at
/batch/multilingual.html.
Canned response to the how to create a zero length file
There are three methods in common use - two of them are operating
system specific:
REM > foo (DOS and Win9x)
copy nul foo (DOS and NT4)
type nul > foo (DOS, Win9x, NT4)