troubleshooting Question

Running a batch file for multiple machines

Avatar of mikewfernandez
mikewfernandez asked on
Microsoft DOS
8 Comments1 Solution598 ViewsLast Modified:
I've created the following script to create and/or remove directories and copy certain files to a workstation. It works great for a few workstations but sometimes I need to run it on more than that. How do I modify the script to do this for all the hostnames in a txt file? I appreciate all the help. I know it might be a little messy but it gets the job done. I'm running Windows 2000/XP.

Thanks,
Mike


echo off
cls

:input
cls
set /p hostname=Enter the name of the workstation you want to update:
if "%hostname%"=="" goto noinput

:verify
echo ============================================================================
echo Verifying if workstation is available...
echo ============================================================================
if exist \\%hostname%\c$ goto location
goto fail

:location
echo ============================================================================
echo Checking file structure...
echo ============================================================================
if exist "\\%hostname%\c$\winnt\profiles\all users" goto winnt
if exist "\\%hostname%\c$\documents and settings\all users" goto allusers

:winnt
echo ============================================================================
echo Copying files...
echo ============================================================================
if exist "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\norton antivirus corporate edition" rmdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\norton antivirus corporate edition" /q /s
rmdir "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5" /q /s
mkdir "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5"
copy \\server\vphome\clt-inst\win32\grc.dat "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5"
copy "\\server\virus definitions\*.vdb" "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5"
if not exist "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki" mkdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki"
if not exist "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\certs" mkdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\certs\"
if not exist "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\cert-signing-requests" mkdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\cert-signing-requests\"
if not exist "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\private-keys" mkdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\private-keys\"
if not exist "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\roots" mkdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\roots\"
copy \\server\vphome\clt-inst\win32\pki\certs\*.* "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\certs"
copy \\server\vphome\clt-inst\win32\pki\cert-signing-requests\*.* "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\cert-signing-requests"
copy \\server\vphome\clt-inst\win32\pki\private-keys\*.* "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\private-keys"
copy \\server\vphome\clt-inst\win32\pki\roots\*.* "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\roots"
cls
goto verifywinnt

:allusers
echo ============================================================================
echo Copying files...
echo ============================================================================
if exist "\\%hostname%\c$\documents and settings\all users\application data\symantec\norton antivirus corporate edition" rmdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\norton antivirus corporate edition" /q /s
rmdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5" /q /s
mkdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5"
copy \\server\vphome\clt-inst\win32\grc.dat "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5"
copy "\\server\virus definitions\*.vdb" "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5"
if not exist "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki" mkdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki"
if not exist "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\certs" mkdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\certs\"
if not exist "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\cert-signing-requests" mkdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\cert-signing-requests\"
if not exist "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\private-keys" mkdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\private-keys\"
if not exist "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\roots" mkdir "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\roots\"
copy \\server\vphome\clt-inst\win32\pki\certs\*.* "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\certs"
copy \\server\vphome\clt-inst\win32\pki\cert-signing-requests\*.* "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\cert-signing-requests"
copy \\server\vphome\clt-inst\win32\pki\private-keys\*.* "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\private-keys"
copy \\server\vphome\clt-inst\win32\pki\roots\*.* "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\roots"
cls
goto verifyallusers

:verifywinnt
echo ============================================================================
echo Verfiying all files were copied...
echo ============================================================================
if not exist "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\grc.dat" goto updatefail
if not exist "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\*.vdb" goto updatefail
if not exist "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki" goto updatefail
if not exist "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\certs" goto updatefail
if not exist "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\cert-signing-requests" goto updatefail
if not exist "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\private-keys" goto updatefail
if not exist "\\%hostname%\c$\winnt\profiles\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\roots" goto updatefail
goto complete

:verifyallusers
echo ============================================================================
echo Verifying all files were copied...
echo ============================================================================
if not exist "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\grc.dat" goto updatefail
if not exist "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\*.vdb" goto updatefail
if not exist "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki" goto updatefail
if not exist "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\certs" goto updatefail
if not exist "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\cert-signing-requests" goto updatefail
if not exist "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\private-keys" goto updatefail
if not exist "\\%hostname%\c$\documents and settings\all users\application data\symantec\symantec antivirus corporate edition\7.5\pki\roots" goto updatefail
goto complete

:complete
echo ============================================================================
echo Update successful. Please re-start the Symantec AntiVirus service on
echo %hostname% to ensure changes take effect.
echo ============================================================================
pause
goto exit

:noinput
echo ============================================================================
echo No workstation was entered. Please enter the name of the workstation
echo you want to update. EXAMPLE: hostname
echo ============================================================================
pause
goto exit

:updatefail
echo ============================================================================
echo Not all files were copied to the workstation. Please verify connection and try again.
echo ============================================================================
pause
goto exit

:fail
echo ============================================================================
echo The workstation you entered is not available. Please verify that it is powered
echo on and alive on the network.
echo ============================================================================
pause
goto exit

:exit
exit
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros