Search code examples
batch-filecmdantivirus

how to check if an antivirus was deactivated or needing something to work properly


I wanna to know how can I check if an antivirus need anything like updating version or required update or needing license to work properly just with CMD or Batch Script thanks a lot


Solution

  • Here is an example script that monitors the productState status and converts it into a variable. I managed to get it working with my specific AntiVirus, but your mileage might vary depending on which one your using.

    I used the productState binary values from here but they can easily be changed by monitoring the values of %byte1% %byte2% %byte3% when your AntiVirus is up-to-date, out-of-date or disabled

    @echo off
    wmic /namespace:\\root\SecurityCenter2 path AntiVirusProduct get * /value|findstr "displayName productState"
    echo.
    set /p dec=Enter productState decimal value to detect state:
    call cmd /c exit /b %dec%
    set "hex=%=exitcode%"
    set "hex=%hex:~2%"
    set "byte1=%hex:~0,2%"&set "byte2=%hex:~2,2%"&set "byte3=%hex:~4,2%"
    :: Check byte1
        set "status1=ANTIVIRUS"
        if "%byte1%"=="00" set "status1=NONE"
        if "%byte1%"=="01" set "status1=FIREWALL"
        if "%byte1%"=="02" set "status1=AUTOUPDATE_SETTINGS"
        if "%byte1%"=="04" set "status1=AVAST_ANTIVIRUS"
        if "%byte1%"=="08" set "status1=ANTISPYWARE"
        if "%byte1%"=="16" set "status1=INTERNET_SETTINGS"
        if "%byte1%"=="32" set "status1=USER_ACCOUNT_CONTROL"
        if "%byte1%"=="64" set "status1=SERVICE"
    :: Check byte2
        set "status2=UNKNOWN"
        if "%byte2%"=="16" set "status2=RUNNING"
    :: Check byte2
        set "status3=UP-TO-DATE"
        if "%byte3%"=="16" set "status3=OUT-OF-DATE"
        if "%byte3%"=="32" set "status3=OUT-OF-DATE"
        if "%byte3%"=="52" set "status3=OUT-OF-DATE"
        if "%byte3%"=="58" set "status3=OUT-OF-DATE"
    
    echo Type of antivirus  : %status1%
    echo Scanning status    : %status2%
    echo Virus definitions  : %status3%
    echo %byte1%
    pause
    

    Of course you'll be better off using proprietary command line tools for specific AV's, but this should work.