Jump to content

detect AV installed on PC !!


Recommended Posts

hello there im trying to modify script i found it in the fourm to check the name and details of installed AV on machine 

#include <Array.au3>


Global Const $___WMI_WBEMFLAGFORWARDONLY = 0x20 ; Causes a forward-only enumerator to be returned. Forward-only enumerators are generally much faster and use less memory than conventional enumerators, but they do not allow calls to 'SWbemObject.Clone_()'.
Global Const $___WMI_WBEMFLAGRETURNIMMEDIATELY = 0x10 ; Causes the call to return immediately.


Local $aAVInfo = _GetAVInfo() ; Local host.

If IsArray($aAVInfo)  Then
    ConsoleWrite( "The  AV Name : " & $aAVInfo[0] & @CRLF  & "The  AV Dir. : " & $aAVInfo[3] & @CRLF)
Else ; Error.
ConsoleWrite("===> No AV installed on This  Machine <==="
EndIf


Func _GetAVInfo($sComputerName = ".")
    Local $aReturn[4]
    Local $oWMIService = ObjGet("winmgmts:\\" & $sComputerName & "\root\SecurityCenter2")
    Local $error = @error

    If Not $error Then
        Local $colItems = $oWMIService.ExecQuery("Select * From AntiVirusProduct", "WQL", $___WMI_WBEMFLAGFORWARDONLY + $___WMI_WBEMFLAGRETURNIMMEDIATELY)
        If IsObj($colItems) Then
            For $colItem In $colItems
                $aReturn[0] = $colItem.displayName

                $aReturn[2] = $colItem.pathToSignedProductExe
                $aReturn[3] = $colItem.pathToSignedReportingExe
            Next

        Else ; Error.
            Return SetError(2, $error)
        EndIf
    Else ; Error.
        Return SetError(1, $error)
    EndIf
    Return $aReturn
EndFunc   ;==>_GetAVInfo

when i run it on PC with installed AV it's working very well i got this output : 

Quote

The AV Name : ESET Internet Security
The AV Dir. : C:\Program Files\ESET\ESET Security\ekrn.exe

 

but when i run it on PC without installed AV i got this output : 

Quote

The  AV Name : 
The  AV Dir. : 

i dont need it to give me that blank lines i need it to execute this line : 

Else 
ConsoleWrite("===> No AV installed on This  Machine <==="

can u help me ...

 

Link to comment
Share on other sites

35 minutes ago, Subz said:
ConsoleWrite("===> No AV installed on This  Machine <===" & @CRLF)

i know that but it's not working on my code check my first code i think there is an issue here : 

If IsArray($aAVInfo)  Then
    ConsoleWrite( "The  AV Name : " & $aAVInfo[0] & @CRLF  & "The  AV Dir. : " & $aAVInfo[3] & @CRLF)
Else ; Error.
ConsoleWrite("===> No AV installed on This  Machine <==="
EndIf

is this right or what : If IsArray($aAVInfo)  Then ?? 

and why i dont get the result of 

Else 
ConsoleWrite("===> No AV installed on This  Machine <==="
EndIf

Link to comment
Share on other sites

It appears that $aAVInfo returns array even if it doesn't find anything, which is why you're getting blank lines, so you would need to use something like:

Local $aAVInfo = _GetAVInfo() ; Local host.
If Not IsArray($aAVInfo) Then $aAVInfo = False
If $aAVInfo = False Or (StringStripWS($aAVInfo[0], 8) = "" And StringStripWS($aAVInfo[3], 8) = "") Then
    ConsoleWrite("===> No AV installed on This  Machine <===" & @CRLF)
Else ; Error.
    ConsoleWrite( "The  AV Name : " & $aAVInfo[0] & @CRLF  & "The  AV Dir. : " & $aAVInfo[3] & @CRLF)
EndIf

 

Link to comment
Share on other sites

8 hours ago, Subz said:

It appears that $aAVInfo returns array even if it doesn't find anything, which is why you're getting blank lines, so you would need to use something like:

Local $aAVInfo = _GetAVInfo() ; Local host.
If Not IsArray($aAVInfo) Then $aAVInfo = False
If $aAVInfo = False Or (StringStripWS($aAVInfo[0], 8) = "" And StringStripWS($aAVInfo[3], 8) = "") Then
    ConsoleWrite("===> No AV installed on This  Machine <===" & @CRLF)
Else ; Error.
    ConsoleWrite( "The  AV Name : " & $aAVInfo[0] & @CRLF  & "The  AV Dir. : " & $aAVInfo[3] & @CRLF)
EndIf

 

thanx u Subz it's working .... but when i try to add it to my code i got this error :  ( my code ) 

#pragma compile(Console, True)
#include <Array.au3>

#include <MsgBoxConstants.au3>
#include <Misc.au3>
Local $hDLL = DllOpen("user32.dll")

ConsoleWrite("coded byy hani |" & @CRLF )
$p = ConsoleWrite("| [ Press 1 ]|" & @CRLF )
$g = ConsoleWrite("| [ Press 2 ]|" & @CRLF )
$i = ConsoleWrite("| [ Press 3 to exit]|" & @CRLF )
$i = ConsoleWrite("_____________________________________________________________" & @CRLF )

While 1
    if _IsPressed("31", $hDLL) Or _IsPressed("61", $hDLL) Then Call("_GetAVInfo")

    if _IsPressed("32", $hDLL) Or _IsPressed("62", $hDLL) Then MsgBox(0,0, "You pressed 2", 1)

    if _IsPressed("33", $hDLL) Or _IsPressed("63", $hDLL) Then
    MsgBox(0,0, "You pressed 3" & @CRLF & "script will exit in 2 second", 2)
    ConsoleWrite("Bye" & @CRLF)
    Exit
    EndIf

    Sleep(50)
WEnd

Global Const $___WMI_WBEMFLAGFORWARDONLY = 0x20 ; Causes a forward-only enumerator to be returned. Forward-only enumerators are generally much faster and use less memory than conventional enumerators, but they do not allow calls to 'SWbemObject.Clone_()'.
Global Const $___WMI_WBEMFLAGRETURNIMMEDIATELY = 0x10 ; Causes the call to return immediately.


Local $aAVInfo = _GetAVInfo() ; Local host.

If Not IsArray($aAVInfo) Then $aAVInfo = False
If $aAVInfo = False Or (StringStripWS($aAVInfo[0], 8) = "" And StringStripWS($aAVInfo[3], 8) = "") Then
    ConsoleWrite("===> No AV. installed on This Machine .... <===" & @CRLF)
Else ; Error.
    ConsoleWrite( "The Fucken AV. Name : " & $aAVInfo[0] & @CRLF  & "The Fucken AV. Dir. : " & $aAVInfo[3] & @CRLF & "The Ducken AV. Mode : " & $aAVInfo[1] & @CRLF )
 EndIf

Func _GetAVInfo($sComputerName = ".")

    Local $aReturn[4]
    Local $oWMIService = ObjGet("winmgmts:\\" & $sComputerName & "\root\SecurityCenter2")
    Local $error = @error

    If Not $error Then
        Local $colItems = $oWMIService.ExecQuery("Select * From AntiVirusProduct", "WQL", $___WMI_WBEMFLAGFORWARDONLY + $___WMI_WBEMFLAGRETURNIMMEDIATELY)
        If IsObj($colItems) Then
            For $colItem In $colItems
                $aReturn[0] = $colItem.displayName
                $aReturn[1] = $colItem.productState
                $aReturn[2] = $colItem.pathToSignedProductExe
                $aReturn[3] = $colItem.pathToSignedReportingExe
            Next
            Switch StringMid(Hex($aReturn[1]), 5, 2)
                Case "00", "01"
                    $aReturn[1] = "Disabled"
                Case "10", "11"
                    $aReturn[1] = "Enabled"
            EndSwitch
        Else ; Error.
            Return SetError(2, $error)
        EndIf
    Else ; Error.
        Return SetError(1, $error)
    EndIf
    Return $aReturn
 EndFunc   ;==>_GetAVInfo

here is my call..... if _IsPressed("31", $hDLL) Or _IsPressed("61", $hDLL) Then Call("_GetAVInfo")

i got this error i dont know why !! 

Quote

1"C:\Users\aaa\Desktop\New AutoIt v3 Script.au3" (48) : ==> Variable used without being declared.:
Local $colItems = $oWMIService.ExecQuery("Select * From AntiVirusProduct", "WQL", $___WMI_WBEMFLAGFORWARDONLY + $___WMI_WBEMFLAGRETURNIMMEDIATELY)
Local $colItems = $oWMIService.ExecQuery("Select * From AntiVirusProduct", "WQL", ^ ERROR

 

Link to comment
Share on other sites

  • Moderators

hani-dev,

When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - responders know what they wrote and it just pads the thread unnecessarily.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@hani-dev The constants were below the call function you would have needed to add them to the top of the script or added it to the local scope see example below:

#pragma compile(Console, True)
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <Misc.au3>

ConsoleWrite("coded byy hani |" & @CRLF )
$p = ConsoleWrite("| [ Press 1 ]|" & @CRLF )
$g = ConsoleWrite("| [ Press 2 ]|" & @CRLF )
$i = ConsoleWrite("| [ Press 3 to exit]|" & @CRLF )
$i = ConsoleWrite("_____________________________________________________________" & @CRLF )

Global $hDLL = DllOpen("user32.dll")
AdlibRegister("Options", 100)
While 1
    Sleep(50)
WEnd

Func Options()
    If _IsPressed("31", $hDLL) Or _IsPressed("61", $hDLL) Then
        Local $aAVInfo = _GetAVInfo()
        If Not IsArray($aAVInfo) Then $aAVInfo = False
        If $aAVInfo = False Or (StringStripWS($aAVInfo[0], 8) = "" And StringStripWS($aAVInfo[3], 8) = "") Then
            ConsoleWrite("===> No AV. installed on This Machine .... <===" & @CRLF)
        Else ; Error.
            ConsoleWrite( "The AV. Name : " & $aAVInfo[0] & @CRLF  & "The AV. Dir. : " & $aAVInfo[3] & @CRLF & "The AV. Mode : " & $aAVInfo[1] & @CRLF )
         EndIf
    EndIf
    If _IsPressed("32", $hDLL) Or _IsPressed("62", $hDLL) Then MsgBox(0,0, "You pressed 2", 1)
    If _IsPressed("33", $hDLL) Or _IsPressed("63", $hDLL) Then
        MsgBox(0,0, "You pressed 3" & @CRLF & "script will exit in 2 second", 2)
        ConsoleWrite("Bye" & @CRLF)
        Exit
    EndIf
EndFunc

Func _GetAVInfo($sComputerName = ".")
    Local Const $___WMI_WBEMFLAGFORWARDONLY = 0x20 ; Causes a forward-only enumerator to be returned. Forward-only enumerators are generally much faster and use less memory than conventional enumerators, but they do not allow calls to 'SWbemObject.Clone_()'.
    Local Const $___WMI_WBEMFLAGRETURNIMMEDIATELY = 0x10 ; Causes the call to return immediately.

    Local $aReturn[4]
    Local $oWMIService = ObjGet("winmgmts:\\" & $sComputerName & "\root\SecurityCenter2")
    Local $error = @error

    If Not $error Then
        Local $colItems = $oWMIService.ExecQuery("Select * From AntiVirusProduct", "WQL", $___WMI_WBEMFLAGFORWARDONLY + $___WMI_WBEMFLAGRETURNIMMEDIATELY)
        If IsObj($colItems) Then
            For $colItem In $colItems
                $aReturn[0] = $colItem.displayName
                $aReturn[1] = $colItem.productState
                $aReturn[2] = $colItem.pathToSignedProductExe
                $aReturn[3] = $colItem.pathToSignedReportingExe
            Next
            Switch StringMid(Hex($aReturn[1]), 5, 2)
                Case "00", "01"
                    $aReturn[1] = "Disabled"
                Case "10", "11"
                    $aReturn[1] = "Enabled"
            EndSwitch
        Else ; Error.
            Return SetError(2, $error)
        EndIf
    Else ; Error.
        Return SetError(1, $error)
    EndIf
    Return $aReturn
 EndFunc   ;==>_GetAVInfo

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...