+ Post New Thread
Results 1 to 6 of 6
Windows Thread, Getting a batch file to react to a registry key in Technical; I have an issue with an antivirus software package. Our technicians used Ghost to image most of the computers, but ...
  1. #1

    Join Date
    Sep 2008
    Location
    Massachusetts
    Posts
    5
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Getting a batch file to react to a registry key

    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!

  2. #2

    Join Date
    Feb 2006
    Location
    Derbyshire
    Posts
    1,381
    Thank Post
    181
    Thanked 211 Times in 171 Posts
    Rep Power
    64
    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.

  3. #3

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,144
    Thank Post
    113
    Thanked 518 Times in 447 Posts
    Blog Entries
    2
    Rep Power
    121
    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:
    Code:
    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:
    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

  4. #4
    tomscaper's Avatar
    Join Date
    Jul 2006
    Posts
    814
    Thank Post
    118
    Thanked 29 Times in 15 Posts
    Rep Power
    21
    I dont know if this would help but could you alter your batch file to including something like the following.

    Code:
    if exist "c:\program files\AV\installed" goto :eof ELSE
    and at the end

    Code:
    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.

  5. #5

    Michael's Avatar
    Join Date
    Dec 2005
    Location
    Birmingham
    Posts
    8,941
    Thank Post
    232
    Thanked 1,510 Times in 1,206 Posts
    Rep Power
    328
    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?

  6. #6

    Join Date
    Sep 2008
    Location
    Massachusetts
    Posts
    5
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Thanks!

    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.

SHARE:
+ Post New Thread

Similar Threads

  1. logoff script to delete registry key
    By ICMC in forum Scripts
    Replies: 3
    Last Post: 26th January 2009, 10:37 PM
  2. [MS Office - 2007] Error 1406: Setup cannot write the value to the registry key
    By Gatt in forum Office Software
    Replies: 1
    Last Post: 13th September 2008, 03:19 PM
  3. Batch file to remove registry key doesnt work
    By sidewinder in forum Windows
    Replies: 4
    Last Post: 7th December 2007, 04:48 PM
  4. Deleted a registry key - help!
    By mrcrazy04 in forum Windows
    Replies: 1
    Last Post: 19th July 2007, 07:26 AM
  5. Script To Change A Registry Key
    By DaveP in forum Windows
    Replies: 6
    Last Post: 7th March 2007, 12:57 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •