Jump to content

Getting a batch file to react to a registry key


Recommended Posts

Posted

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!

Posted

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.

Posted

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:

if errorlevel 1 goto end
rem reinstall SAV

:end
echo SAV installed

 

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:

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

Posted

I dont know if this would help but could you alter your batch file to including something like the following.

 

if exist "c:\program files\AV\installed" goto :eof ELSE

 

and at the end

 

md "c:\program files\AV\installed"

 

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.

 

PM if you want any more info.

Posted
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?
Posted

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...