Tuesday, March 2, 2010

Keeping Track of Files

Ever wanted to make sure the same file, in this case hosts file, is on all the PCs you manage at the office, but you don't have the budget for expensive automated software distribution tools?  You can do this with DOS batch or .VBS files.

Make a directory that we have permissions to write into at login.  In that directory create a marker file so we can successfully check to see if the directory exists.  Then we use the same technique to check the version of our hosts file!

Here's the code ...

@echo off
cls
echo *****************************************************************
echo * Executing Login Scripts.  Use of this equipment is restricted *
echo * to authorized employees only.                             *
echo *****************************************************************
echo .

:PCUPDATE

IF EXIST "c:\patches\NULL" GOTO :HOSTSNT

cd c:\
mkdir PATCHES
cd c:\patches
dir > NULL

:HOSTSNT

IF EXIST "c:\patches\hosts.20070430" GOTO END

echo Updating Hosts file

cd %SYSTEMROOT%\system32\drivers\etc
copy hosts hosts.old /Y
copy \\FileServer1\Sys\Patches\hosts . /Y > c:\patches\hosts.20070430

echo Done.

:END

We create the directory if it doesn't exist as previously discussed.  Then we look for a hosts file revisioned 20070430 (yyyymmdd).  If the file doesn't exist then we: 1. create a backup of our existing hosts file and 2. copy the new hosts file from our network store sending the output to our marker file in c:\patches.

No comments:

Post a Comment