System maintenance program for Vista/XP/2000: help needed

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mgrahek
Posts: 13
Joined: 29 Aug 2008 08:24

System maintenance program for Vista/XP/2000: help needed

#1 Post by mgrahek » 12 Sep 2008 18:13

This is my first real batch program and it is FUN!! I'm looking at making this a comprehensive program that has MANY features. I'm looking for anyone who wants to help with programming sections (adding additional AV program selections) and system maintenance.

I welcome any and all advice/suggestions/contributions here and would love someone to work on some sections as well.

I've thought of some things to add and wondered if they would be possible:
****Upon connecting to a Wireless LAN or a LAN, automatically run a script that will automatically map drives associated with that network. THIS WOULD BE AWESOME!!!!! 2nd highest priority!
*** Automatically enable/change proxy settings in Internet options and Firefox when a specific LAN is connected to
**Shutdown/restart/logoff (forced/remote??)
*Locate other computers (by name & IP address) on the network
*send commands to remote PC's


Some things I'd like to add are service pack updates, auto detection of NT version, which would remove the step of asking "are you running Vista, XP or 2000"

I'm going to post the code and feel free to browse. If you think there should be modifications, please let me know and be specific so I can understand where it needs to be fixed.

http://www.tuprox.com/input12.bat

Code: Select all

Echo off
FOR /F "usebackq tokens=1-4,* delims=/ " %%a IN ('%date%') DO (set datestring=%%d-%%b-%%c)
set logfile=c:\logs\%computername%-Sophos-AV-Scan-%datestring%.log

:start
cls
Echo Welcome to System Maintenance setup.
Echo Please select the type of OS you wish to
Echo install this program onto:
Echo 1:  Windows 2000
Echo 2:  Windows XP
Echo 3:  Windows Vista
Echo Q:  Quit
choice /c:123Q
if errorlevel 1 set OS#=1
if errorlevel 2 set OS#=2
if errorlevel 3 set OS#=3
if errorlevel 1 set OSname=Windows 2000
if errorlevel 2 set OSname=Windows XP
if errorlevel 3 set OSname=Microsoft Vista
if errorlevel 4 goto Quit
if errorlevel 3 goto menu
if errorlevel 2 goto menu
if errorlevel 1 goto menu
***************************************************

:menu
cls
echo YOU HAVE REACHED THE MENU!!!!
echo You have choosen %OSname%
echo What would you like to schedule?  Please
echo select (Q) to Quit or (C) to continue:
echo.
Echo 0:  Schedule Task
echo 1:  Disk Cleanup
echo 2:  Scan Disc
echo 3:  Defragment
echo 4:  Anti-Virus Scan
echo 5:  System Backup
echo 6:  Registry Cleanup
echo 7:  Remote Administration (enable/disable)
echo 8:  Configure Network
echo Q:  Quit
choice /c:12345678Q
if errorlevel Q goto quit
if errorlevel 8 goto network
if errorlevel 7 goto remadmin
if errorlevel 6 goto regclean
if errorlevel 5 goto sysbak
if errorlevel 4 goto avscan
if errorlevel 3 goto defrag
if errorlevel 2 goto scandisc
if errorlevel 1 goto discclean
goto semiend
***************************************************

:discclean
echo You have selected Disc Cleanup
pause
goto semiend



***************************************************
:scandisc
echo You have selected Scan Disc
pause
goto semiend




***************************************************
:defrag
echo You have selected Defragment
pause
goto semiend



***************************************************
[b]:avscan
cls
Echo.
echo You have selected to run an anti-Virus Scan
echo.
echo Please enter the drive to scan.
echo C: Drive
echo D: Drive
echo E: Drive
echo X: I selected the wrong AV program
choice /c:CDEX
if errorlevel 1 set avdrivescan=C:
if errorlevel 2 set avdrivescan=D:
if errorlevel 3 set avdrivescan=E:
if errorlevel 4 goto avscan
cd\
mkdir logs
cd\logs
mkdir Sophos
set savlog=c:\logs\Sohpos\SophosAV-%avdrivescan%-%datestring%.log
cls


echo You have choosen %avdrivescan%\ to be scanned
echo for viruses.
echo.
CHOICE /C YN /M "Do you want to do a full scan of the selected drive?"
if errorlevel 2 goto avscanpath
if errorlevel 1 goto avoptions

 
:avoptions
cls
echo.
echo What options would you like to include on the scan?
echo.
echo 1. Disinfect, remove, MBR, archive, full, recessive, logging
echo 2. Full scan only (will not disinfect or remove threats) w/ logging
echo 3. Custom Scan
choice /c:123
if errorlevel 3 goto avchoice
if errorlevel 2 goto avscan2
if errorlevel 1 goto avscan1

:avscanpath


:avchoice
cls
echo You have selected Anti-Virus Scan
echo.
echo What Anti-Virus program is on your system?
echo.
echo A: AVG
echo S: Sophos
choice /c:AS
if errorlevel 1 set /A AVnum=1
if errorlevel 2 set /A AVnum=2
if errorlevel 2 goto sophos1
if errorlevel 1 goto avg1


:sophos1
set av=Sophos
goto sophoscustom

:avg1
set av=AVG
goto avgcustom





:sophoscustom
cls
echo You have chosen %av% Anti-Virus
Echo Please select the options to include in the scan:
echo.
Echo Please select the options that you wish to enable
echo Select "Y" for yes and "N" for No
echo.
CHOICE /C YN /M "Scan inside dynamically compressed executables"
if errorlevel 1 set av1=-sc
if errorlevel 2 set av1=

CHOICE /C YN /M "Full scan"
if errorlevel 1 set av2=-f
if errorlevel 2 set av2=

CHOICE /C YN /M "Disinfect infected items"
if errorlevel 1 set av3=-di
if errorlevel 2 set av3=

CHOICE /C YN /M "Run silently (do not list files swept)"
if errorlevel 1 set av4=-s
if errorlevel 2 set av4=

CHOICE /C YN /M "Ask for confirmation before disinfection/deletion"
if errorlevel 1 set av5=-c
if errorlevel 2 set av5=

CHOICE /C YN /M "Sound bell on virus detection"
if errorlevel 1 set av6=-b
if errorlevel 2 set av6=

CHOICE /C YN /M "Scan all files"
if errorlevel 1 set av7=-all
if errorlevel 2 set av7=

CHOICE /C YN /M "Do recursive scan"
if errorlevel 1 set av8=-rec
if errorlevel 2 set av8=

CHOICE /C YN /M "Remove infected objects"
if errorlevel 1 set av9=-remove
if errorlevel 2 set av9=

CHOICE /C YN /M "Display names of files as they are scanned"
if errorlevel 1 set av10=-dn
if errorlevel 2 set av10=

CHOICE /C YN /M "Display nothing except on error or virus"
if errorlevel 1 set av11=-ss
if errorlevel 2 set av11=

CHOICE /C YN /M "Write to log file
if errorlevel 1 set av12=-p=
if errorlevel 2 set av12=

CHOICE /C YN /M "Scan master boot records on all hard disks"
if errorlevel 1 set av13=-mbr
if errorlevel 2 set av13=

CHOICE /C YN /M "Scan boot sector of each drive listed"
if errorlevel 1 set av14=-bs=
if errorlevel 2 set av14=

CHOICE /C YN /M "Scan for Macintosh viruses"
if errorlevel 1 set av15=-mac 
if errorlevel 2 set av15=

CHOICE /C YN /M "Scan boot sector in bootable image of each CD drive listed"
if errorlevel 1 set av16=-cdr=
if errorlevel 2 set av16=

hostname>>%logfile%
whoami>>%logfile%
date /T>>%logfile%
time /T>>%logfile%

hostname>>%savlog%
whoami>>%savlog%
date /T>>%savlog%
time /T>>%savlog%

echo savcli32.exe %av1%%av2%%av3%%av4%%av5%%av6%%av7%%av8%%av9%%av10%%av11%%av12%%savlog% %av13%%av14%%avdrivescan% %av15%%av16%%

REM Print time of completion
time /T>>%savlog%
date /T>>%savlog%

time /T>>%logfile%
date /T>>%logfile%
type %savlog%>>%logfile%




cd\program files\sophos\sophos anti-virus\
sav32cli c: -f -b -remove -sc -nc -mbr -bs=c: -all -rec -di -archive -

p=c:\logs\SophosAV-c.log
type c:\logs\SophosAV-%avdrivescan%.log>>c:\logs\%computername%-SophosAV-%

datestring%.log

REM Print time of completion
time /T>>c:\logs\SophosAV.log




echo.
echo SophosCustom sub section is now done
pause
goto quit
[/b]*******************

:avgcustom
cls
echo You have chosen %av% Anti-Virus

goto avcustomsub


:avscan1
echo %av% Anti-Virus is performing a full scan
echo of your computer.  Please be patient and let
echo the process complete.  You may minimize this
echo screen if necessary.
echo This may take many hours to complete.
pause
Echo off
REM Change to working directory
cd\program files\sophos\sophos anti-virus\

hostname>>%logfile%
whoami>>%logfile%
date /T>>%logfile%
time /T>>%logfile%

REM Sophos Scan and clean
cd\program files\sophos\sophos anti-virus\
sav32cli c: -f -b -remove -sc -nc -mbr -bs=c: -all -rec -di -archive -

p=c:\logs\SophosAV-c.log
type c:\logs\SophosAV-%avdrivescan%.log>>c:\logs\%computername%-SophosAV-%

datestring%.log

REM Print time of completion
time /T>>c:\logs\SophosAV.log
pause

:avscan2







pause
***************************************************
goto semiend



:sysbak
echo You have selected System Backup
pause
goto semiend


***************************************************
:regclean
echo You have selected Registry Cleaner
pause
goto semiend


***************************************************
:remadmin
echo You have selected Remote Administration
pause
goto semiend



***************************************************
:network
echo You have selected Configure Network
pause
goto semiend




***************************************************
:Quit
cls
echo You have choosen to exit the configuration.
CHOICE /C YN /M "Do you really want to exit?"
if errorlevel 2 goto start
if errorlevel 1 goto end
pause
***************************************************

:Semiend
echo something happened in the program that isnt' supposed to
echo please debug the program
goto start

:end
set osname=
set os#=


This is a work in progress, so please don't mind the sloppyness. It will be cleaned up as I go. The AV section is a mess but will be cleaned up.

What would you add to this program? What features would be good to add?

Ideas greatly appreciated!!
Last edited by mgrahek on 12 Sep 2008 18:38, edited 3 times in total.

mgrahek
Posts: 13
Joined: 29 Aug 2008 08:24

#2 Post by mgrahek » 12 Sep 2008 18:29

I'm on a part that is a little confusing to me. I have a current version that asks questions that have a Y/N answer. The yes answer sets the variable to the proper switch that is needed to execute the procedure. This is what it looks like when it is run.

Image

This image is a shot of how I had it setup before


Image

But I was having problems when trying to select individual switches For example, if I were to select D, it would select A, B, C, D

Image

Here is the code that I was working with at the time... I've learned a lot about what I've been doing since then, but this is what I had. I feel that my main problem is using the "if errorlevel" command to make this work..

http://www.tuprox.com/input6.bat

Code: Select all

:AVSECTION

:avscan
cls
echo You have selected Anti-Virus Scan
echo.
echo What Anti-Virus program is on your system?
echo.
echo A: AVG
echo S: Sophos
choice /c:AS
if errorlevel 1 set AV=AVG
if errorlevel 2 set AV=Sophos
cls
echo.
echo You have selected %AV%
echo.
echo Please enter the drive to scan.
echo C: Drive
echo D: Drive
echo E: Drive
echo X: I selected the wrong AV program
choice /c:CDEX
if errorlevel 1 set avdrivescan=c:
if errorlevel 2 set avdrivescan=d:
if errorlevel 3 set avdrivescan=e:
if errorlevel 4 goto avscan

echo.
CHOICE /C YN /M "Do you want to do a full scan of the selected drive?"
if errorlevel 1 goto avoptions
if errorlevel 2 goto avscanpath
 
:avoptions
cls
echo.
echo What options would you like to include on the scan?
echo.
echo 1. Disinfect, remove, MBR, archive, full, recessive, logging
echo 2. Full scan only (will not disinfect or remove threats) w/ logging
echo 3. Custom Scan
choice /c:123
if errorlevel 3 goto avcustom
if errorlevel 2 goto avscan2
if errorlevel 1 goto avscan1



:avcustom
cls
set offa=( )
set offb=( )
set offc=( )
set offd=( )
set offe=( )
set offf=( )
set offg=( )
set offh=( )
set offi=( )
set offj=( )
set offk=( )
set offl=( )
set offm=( )
set offn=( )
set offo=( )
set offp=( )
set ona=(*)
set onb=(*)
set onc=(*)
set ond=(*)
set one=(*)
set onf=(*)
set ong=(*)
set onh=(*)
set oni=(*)
set onj=(*)
set onk=(*)
set onl=(*)
set onm=(*)
set onn=(*)
set ono=(*)
set onp=(*)
:avcustomsub
cls
Echo Please select the options to include in the scan:
echo.
echo A: %offa% Scan inside dynamically compressed executables
echo B: %offb% Full scan
echo C: %offc% Disinfect infected items
echo D: %offd% Run silently (do not list files swept)
echo E: %offe% Ask for confirmation before disinfection/deletion
echo F: %offf% Sound bell on virus detection
echo G: %offg% Scan all files
echo H: %offh% Do recursive scan
echo I: %offi% Remove infected objects
echo J: %offj% Display names of files as they are scanned
echo K: %offk% Don't display anything except on error or virus
echo L: %offl% Write to log file
echo M: %offm% Scan master boot records on all hard disks
echo N: %offn% Scan boot sector of each drive listed
echo O: %offo% Scan for Macintosh viruses
echo P: %offp% Scan boot sector in bootable image of each CD drive listed
echo.
echo Z: Start Scan
echo.
echo. Please select the letter with the appropriate selection
choice /c:ABCDEFGHIJKLMNOPZ
pause
if errorlevel = 16 set offp=(*)
if errorlevel = 15 set offo=(*)
if errorlevel = 15 set offo=(*)
if errorlevel = 14 set offn=(*)
if errorlevel = 13 set offm=(*)
if errorlevel = 12 set offl=(*)
if errorlevel = 11 set offk=(*)
if errorlevel = 10 set offj=(*)
if errorlevel = 9 set offi=(*)
if errorlevel = 8 set offh=(*)
if errorlevel = 7 set offg=(*)
if errorlevel = 6 set offf=(*)
if errorlevel = 5 set offe=(*)
if errorlevel = 4 set offd=(*)
if errorlevel = 3 set offc=(*)
if errorlevel = 2 set offb=(*)
if errorlevel = 1 set offa=(*)
goto avcustomsub

A sc
B f
C di
D s
E c
F b
G all
H rec
I remove
J dn
K ss
L p=
M mbr
N bs=
O mac
P cdr=


:avscan1
echo %av% Anti-Virus is performing a full scan
echo of your computer.  Please be patient and let
echo the process complete.  You may minimize this

echo screen if necessary.
echo This may take many hours to complete.
pause
Echo off
REM Change to working directory
cd\program files\sophos\sophos anti-virus\

hostname>>c:\log\SophosAV.log
whoami>>c:\log\SophosAV.log
date /T>>c:\log\SophosAV.log
time /T>>c:\log\SophosAV.log

REM Sophos Scan and clean
c:\program files\sophos\sophos anti-virus\sav32cli c: -f -b -remove -sc -nc -mbr -bs=c: -all -rec -di -archive -p=c:\logs\SophosAV-c.log
type c:\logs\SophosAV-c.log>>c:\logs\SophosAV.log

REM Print time of completion
time /T>>c:\logs\SophosAV.log
pause

:avscan2

:avscanpath
[/url]

Post Reply