5. Batch, batch and more batch...


I was reading the alt.2600 newsgroup the other day and during a thread, someone mentioned how much he missed playing in batch files to automates his tasks, recollect info from PCs, ... Batch files are to Microsoft administrators what shell scripts are to UNIX hackers. Too bad this is now a lost art in the MS community.

If you like batch files, it's only up to you to use them. You'll be surprised what you can do with them with some imagination. And to think they wanted me to purchase a multi-K $ system to take care of this chore. The antivirus product proved to be more and more stable, even if a small glitch was causing the current (live) virus scanner to jam while scanning the executables of the new version. I could not figure out a pattern to this problem, as it proved to happen randomly. This appeared first on a few IBM laptops, and I thought it was an IBM related problem, but I had several identical machines updated successfully. Then the problem appeared on some Dell PCs. This was (or appeared to be) random, and even if this didn't happen that often, it was still annoying. It was happening too often. I decided to take a shot at it anyway.

This was getting complicated, because the installation process required three reboots to be completed. Also, at around 3.5 or 3.6, McAfee moved some configuration information away from the ASCII files to put it in the registry. Playing in the registry from a batch file! What was I on? Now, with the experience I have, this isn't probably as bad as it sounds. I'm pretty sure that there's a command out there that let's you add registry keys at the command prompt. But at the time, I was a bit puzzled.

This needed condition handling, installation step recognition over several reboot cycles, and registry fiddling. That didn't prove to be so hard. I created dummy flag files, namely called flag1.dum, flag2.dum and so on. I copied them on the machine at different steps in the process, and I could rely on the presence or absence of these files to determine where the batch file had to pick up after a reboot. As for the registry settings I needed to transplant, all I had to do was to export the corresponding registry hive containing the relevant information from a properly configured machine. That would give me a file called update.reg. Then I would copy that file to the Startup folder, which on reboot will merge the hive in the registry, putting it up to date. Only one drawback, minor in fact, this will present a dialog box to the user saying that the registry had successfully been updated, with a OK button. Not much, but I would have liked to do it with zero-interaction. The usage of flag#.dum files made it so that I had to manage them. Since I was making this up on the run, I didn't take time to see if I could make it simpler. Here's what it looked like, along with comments. Note the OS version checking at the beginning, useful if your site is mixed with Win95/98/NT. Different Windows versions sometimes mean different path or files, so you may need a batch file for each.

Rem McAfee remote installer - No more one-by-one installs
Rem By Floydman
:Vertest
@echo off

ver > c:\ver.txt

Rem This works by matching the OS name string to the output of ver.exe
Rem If there's a match, it is piped to ver(n).txt, if there's no match, the file is empty
Rem Then ver(n).txt is copied to ver(n+1).txt
Rem Copying an empty file produces no file copied at all
Rem So if ver(n+1).txt exists, we know the OS,
Rem If not check next version until all are checked

:Windows NT
type c:\ver.txt |find "Windows NT" > c:\ver4.txt
copy c:\ver4.txt c:\ver5.txt
if exist c:\ver5.txt goto Endfinal

:Windows 95
type c:\ver.txt |find "Windows 95" > c:\ver2.txt
copy c:\ver2.txt c:\ver3.txt
if exist c:\ver5.txt goto Win95

:Unknown OS
echo ERROR: OS cannot be identified.
goto Endfinal

:Win95

Rem some cleanup
erase c:\ver*.txt >nul

echo This will install the latest McAfee antivirus software
echo with the proper configuration
echo

:Install
Rem If this step is done, proceed to the next step
if exist c:\flag3.dum goto cleanup
Rem Display installation notice contained in a .txt file
c:\windows\notepad.exe \\servername\misc\install.txt
xcopy \\servername\misc\flag3.dum c:\ >nul

Rem Copy installation directory on C: drive
echo Copying installation files (this will take about 30 minutes on DialUp connections)

Rem Create temp directory for installation
c:
cd\
md mcinst
cd mcinst
xcopy \\servername\upgrade\*.* >nul

Rem Starts installation routine
echo Silent installation begins...
setup -s
goto End

:Cleanup
Rem If this step is done, proceed to the next step
if exist c:\flag4.dum goto Final
Rem Back up the registry
attrib -h -s c:\windows\system.dat >nul
attrib -h -s c:\windows\user.dat >nul
copy c:\windows\system.dat c:\windows\system._da >nul
copy c:\windows\user.dat c:\windows\user._da >nul
attrib +h +s c:\windows\system.dat >nul
attrib +h +s c:\windows\user.dat >nul

Rem Copy registry update to be executed at startup
echo modifying registry setings...
xcopy \\servername\config\update.reg c:\windows\startm~1\programs\startup\ >nul

Rem Remove installation directory that is no longer required
c:\windows\deltree /Y c:\mcinst >nul

Rem Remove old flag files from previous installations
if exist c:\flag1.dum erase c:\flag1.dum >nul
if exist c:\flag2.dum erase c:\flag2.dum >nul

xcopy \\servername\misc\flag4.dum c:\ >nul
goto End

:Final
Rem Check if last step is done
if exist flag5.dum goto End
Rem Remove registry update from startup folder to avoid numerous registry updates
erase c:\windows\startm~1\programs\startup\update.reg >nul
xcopy \\servername\misc\flag5.dum >nul
goto End

:End
Rem Updates the configuration files if needed.
Rem Don't forget the files on server NEED to be a year or do forward
xcopy \\servername\update\*.vs? c:\progra~1\McAfee\ /q /y /d
xcopy \\servername\update\avconsol.ini c:\progra~1\McAfee\ /q /y /d

:Endfinal
echo

People new to batch files, or to programming in general (as is often the case with new NT system admins) will notice three principal characteristics about this program that makes it quite a good piece of batch file. First, it is well documented. Second, it tells the user what is happening as it happens, but actually hiding the real output to them. Third, it cleans itself up (unlike several commercial programs on the market). The rest is just logic applied. On top of it, I'd say I made it deadly accurate. There wasn't really a need to specify all path names when calling commands. Make sure you have your batch file to correspond your path structure on the server (upgrade, update, misc and config directories) along with the needed files. Install.txt is actually an ASCII file containing a message explaining that a software install is currently going on, along with my coordinates if they have any questions or problems. Usually, system admins would like to hear as less as possible from their users, and would like having their phone number/pager number in circulation as less as possible. To some people, broadcasting their coordinates to their users would be like "advertising" their services, making people think "about that little quirk on my machine that is no really big deal, but since you reminded me..." I would say the opposite. The fact alone that my full name, title and phone number (instead of just "The support team") is listed is enough to inspire faith in the most fearsome user. I would point out to something else: remember when we used to have a dull presentation at school (or even at work) and the teacher would ask, "Anyone have a question? Anyone?" and nobody raised their hand? Well that still works today, even if phone call or e-mail is more discreet to admit ignorance than raising a hand in front of people. So sign your message with "So if you have any questions, Anyone? Contact me at ###-####". You'd be surprised how effective this is to prevent annoying phone calls.

4. Then came Autoupdate
6. McAfee Customer Support

Table of contents

Hosted by www.Geocities.ws

1