1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Batch issue with McAfee

Discussion in 'DOS/Other' started by raven6988, Apr 20, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. raven6988

    raven6988 Thread Starter

    Joined:
    Feb 4, 2010
    Messages:
    28
    On my last topic I was having the problems with the errors displaying and that fix worked great... but I ran into a little problem with the way my McAfee Virus Definitions are displaying since I added that to the mix to show which machines had McAfee installed and which Virus Defs were working.

    While I have figured out how to get it to show everything I need it is still showing a slight error of the side. Keeps saying this is a "Missing operand."

    Here is the code to see where I am missing something or what is going on. The way it currently is works just fine when there is McAfee installed but if nothing is found it shows the "Missing operand." and still shows the echo for not found. The /A is because it is in hex and I need the value in decimal.

    Set _MCAFVER=
    FOR /F "tokens=2* delims= " %%A ('REG Query "HKLM\SOFTWARE\McAfee\AVEngine" /v AVDatVersion 2^>Nul') DO (
    Set _MAVDATVER=%%B
    )
    Set /A _MAVDATVER=%_MAVDATVER%
    If "%_MAVDATVER%"=="" (
    echo . McAfee Virus Definitions no Found.
    ) Else (
    echo . Virus Def Ver %_MAVDATVER% Installed.
    )



    I am at a lose because I have tried everything that I know to move the Set /A around to make it work with both but I can not find the correct spot.
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Do you have Echo on or Off.
    A good way to troubleshoot this is to have it echo everything to the console and examine the output of each command.
     
  3. raven6988

    raven6988 Thread Starter

    Joined:
    Feb 4, 2010
    Messages:
    28
    Here is what it comes up with

    Set _MCAFVER=

    FOR /F "tokens=2* delims= " %%A ('REG Query "HKLM\SOFTWARE\McAfee\AVEngine" /v AVDatVersion 2^>Nul') DO (Set _MAVDATVER=%B )

    Set /A _MAVDATVER=
    Missing operand.

    If "%_MAVDATVER%"=="" (echo . McAfee Virus Definitions no Found.) Else (echo . Virus Def Ver Installed.)
    . McAfee Virus Definitions not Found.


    So my question is how can I stop it from showing that missing operand when nothing is there to set to decimal?
     
  4. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    You can't do math on an undefined variable.
    Code:
    H:\>set _MAVDATVER=
    
    H:\>set /a _MAVDATVER=%_MAVDATVER%
    Missing operand.
    
    H:\>
     
  5. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Code:
    If "%_MAVDATVER%"=="" (
    echo . McAfee Virus Definitions no Found.
    ) Else (
    set /A _MAVDATVER=%_MAVDATVER%
    echo . Virus Def Ver %_MAVDATVER% Installed.
    )
     
  6. raven6988

    raven6988 Thread Starter

    Joined:
    Feb 4, 2010
    Messages:
    28
    Yes I understand that you can not do math with an undefined variable. What I am trying to find is how I can put the

    Set /A _MAVDATVER=%_MAVDATVER%

    Somewhere after the else statement and make it convert? I get rid of the missing operand if I drop it down after the Else but I can not get it to convert the variable unless it is at the top.

    For Example if I do:

    Set _MCAFVER=
    FOR /F "tokens=2* delims= " %%A ('REG Query "HKLM\SOFTWARE\McAfee\AVEngine" /v AVDatVersion 2^>Nul') DO (
    Set _MAVDATVER=%%B
    )
    If "%_MAVDATVER%"=="" (
    echo . McAfee Virus Definitions no Found.
    ) Else (
    Set /A _MAVDATVER=%_MAVDATVER%
    echo . Virus Def Ver %_MAVDATVER% Installed.
    )

    The error goes away but now I can get the Dat Version in Decimel... only Hex. I am stumped... I am not sure what I am missing to complete this.
     
  7. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Need to use delayed expansion So your variable needs to be surrounded by exclamation points in the echo.

    Code:
    SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
    set _MAVDATVER=0x0001e240
    If "%_MAVDATVER%"=="" (
    echo . McAfee Virus Definitions no Found.
    ) Else (
    Set /A _MAVDATVER=%_MAVDATVER%
    echo . Virus Def Ver !_MAVDATVER! Installed.
    )
    output
    Code:
    E:\batch files>SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
    
    E:\batch files>set _MAVDATVER=0x0001e240
    
    E:\batch files>If "0x0001e240" == "" (echo . McAfee Virus Definitions no Found.
    )  Else (
    Set /A _MAVDATVER=0x0001e240
     echo . Virus Def Ver !_MAVDATVER! Installed.
    )
    . Virus Def Ver 123456 Installed.
     
  8. raven6988

    raven6988 Thread Starter

    Joined:
    Feb 4, 2010
    Messages:
    28
    Thank you... That fixed it. I completely forgot about the extensions and delay. Thank you again for the help. It is greatly appreciated.
     
  9. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    If you don't want to use delayed expansion then this would work

    Code:
    Set _MCAFVER=
    set _MAVDATVER=
    FOR /F "tokens=2* delims= " %%A ('REG Query "HKLM\SOFTWARE\McAfee\AVEngine" /v AVDatVersion 2^>Nul') DO (
    IF NOT "%%B"=="" Set /a _MAVDATVER=%%B
    )
    If "%_MAVDATVER%"=="" (
    echo . McAfee Virus Definitions no Found.
    ) Else (
    echo . Virus Def Ver %_MAVDATVER% Installed.
    )
     
  10. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/918031

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice