I have an issue with an antivirus software package. Our technicians used Ghost to image most of the computers, but didn't follow the procedures for the AV. I have a batch file that will remove the software and re-install it through a GPO. However, once the GPO runs once, we don't want it to continue re-installing over and over.
I have the following line in the file at the end of the removal process:
ECHO Installation of a new registry key..
REG ADD HKLM\SOFTWARE\SAVREINSTALLED /v DATA /t REG_Z
At the beginning of the batch file, I have the following:
ECHO Checking for previous installations...
REM Error Levels 0=Successful, the result compared is different
REM 1=Failed
REM 2=Successful, the result compared is different
REG COMPARE HKLM\SOFTWARE HKLM\SOFTWARE\SAVREINSTALLED
if %errorlevel% equ 1(
Echo SAV already installed, aborting the script
pause
Echo.
) ELSE Exit
When I run the batch file, it just stops and closes. When I run the REG commands seperately, I get the results I'm looking for (Generating the key, checking it, etc).
Now, I need to tie it all together. I'm not really good at programming, so I'm sure the problem is in how I'm checking the compare function.
Can anyone please help me out here? My only other option isd to individually visit every computer here on campus (over 500)!!!
Thanks!
Off the top of my head, doesn't that try and compare a string version of errorlevel to the number 1?
if %errorlevel% equ 1(
This would explain it jumping past your comparison and closing the batch.
Or are you saying that even that works correctly when typed in a console window?
If it was me, I'd add an
echo %errorlevel%
PAUSE
at the end of the batch file so you can see the output and go from there.
Does it have to be a batch file? It's an awful lot easier to do this in a language like vbscript.
I haven't used batch files like this for ages, but I thought the syntax was:
The other thing I've done in the past is just write a flag file to some location - you can then use something like this:Code:if errorlevel 1 goto end rem reinstall SAV :end echo SAV installed
Code:if exist c:\windows\sav.flag goto end rem need to install rem run install process rem now write flag file echo dummy text > c:\windows\sav.flag :end echo SAV installed
I dont know if this would help but could you alter your batch file to including something like the following.
and at the endCode:if exist "c:\program files\AV\installed" goto :eof ELSE
Replacing the location for a folder to be created somewhere, the script will load each time but if that folder has been created then install part should be skipped.Code:md "c:\program files\AV\installed"
PM if you want any more info.

I agree that for something like this a vbscript would be better. You could in theory run the vbscript file/command within a batch file. Just an idea?
Thanks to all of you who responded so quickly.
The original script was supplied "as is" from the software company, and was in a .BAT format. I'm not a programmer, so it was easier to stick with the batch file. The suggestion about creating andf then checking on a null type folder worked best for me. Thanks Tomscaper!
I've tested it, and it works just fine.
Again, thank you to all who responded.
There are currently 1 users browsing this thread. (0 members and 1 guests)