0

I'm trying to get the status of AntiVirus from Windows Security Center 2 in Windows 7 or 8. I can pull the data from the "objAntiVirusProduct.displayName" and display the information, however I can't seem to make the Hex work correctly. Here's what I have right now.

Dim objWMIServiceAV,objAntiVirusProduct,colFiles,colItems,itemFile,AvStatus,PathToSignedProductExe
Dim strdisplayName,strproductState,strdefinitionState

Set objWMIServiceAV = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\SecurityCenter2") 
Set colItems = objWMIServiceAV.ExecQuery("Select * from AntiVirusProduct")
For Each objAntiVirusProduct In colItems 
    Set colFiles = objWMIServiceAV.ExecQuery ("Select * from CIM_Datafile Where name = '" & PathToSignedProductExe & "'",,48) 
    For Each itemFile In colFiles
        strdisplayName = (objAntiVirusProduct.displayName)  
        AvStatus = Hex(objAntiVirusProduct.ProductState)
        If Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" Then
            strproductState = "Scanning Enabled"
        ElseIf Mid(AvStatus, 2, 2) = "00" Or Mid(AvStatus, 2, 2) = "01" Then
            strproductState = "Scanning Not Enabled" 
            errors("AntiVirus Product State: ") = "Off"
        End If

        If Mid(AvStatus, 4, 2) = "00" Then
            strdefinitionState = "AntiVirus up-to-date"
        ElseIf Mid(AvStatus, 4, 2) = "10" Then
            strdefinitionState = "AntiVirus outdated"
        End If

        objFile.Write "AntiVirus Display Name= " & strdisplayName & vbNewLine
        objFile.Write "AntiVirus Scanning Status= " & strproductState & vbNewLine
        objFile.Write "AntiVirus Definition Status= " & strdefinitionState & vbNewLine
    Next 
Next 

What am I missing?

EDIT: I've been asked to provide some examples of my output.

What I'm receiving is:

AntiVirus Display Name= Norton Endpoint Protection
AntiVirus Scanning Status= 
AntiVirus Definition Status= 

What I'm expecting is:

AntiVirus Display Name= Norton Endpoint Protection
AntiVirus Scanning Status= (SCANNING STATUS)
AntiVirus Definition Status= (AV UPDATE STATUS)
Mojoscream
  • 51
  • 1
  • 12
  • Please give an example of actual and desired output. It would also be good practice to trim your code down to a minimal example that still demonstrates the problem. – Ansgar Wiechers Jun 18 '14 at 21:11
  • I added in my output. The "objAntiVirusProduct.ProductState" outputs a number, and I'm trying to read specific values of that number. My problem is that for whatever reason I'm not getting any kind of output for either the "Scanning Status" or "Definition Status". – Mojoscream Jun 19 '14 at 17:23
  • Looks like hex characters 3 through 6 don't match the patterns you're checking for. Add a line `WScript.Echo AvStatus` after the line `AvStatus = Hex(objAntiVirusProduct.ProductState)`. What value do you get? – Ansgar Wiechers Jun 19 '14 at 19:07

1 Answers1

0

Find out what my issue was, I was essentially doubling up the amount of work needed to accomplish the task. What I did was I removed lines 8 & 9, this got everything working correctly. I also went through and removed variables that were no longer needed, and prettied things up a bit more.

My finished code looks like this:

Dim objWMIServiceAV,objAntiVirusProduct,colItems
Dim strdisplayName,AvStatus,strproductState,strdefinitionState

Set objWMIServiceAV = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\SecurityCenter2") 
Set colItems = objWMIServiceAV.ExecQuery("Select * from AntiVirusProduct")
For Each objAntiVirusProduct In colItems 
    strdisplayName = (objAntiVirusProduct.displayName)  
    AvStatus = Hex(objAntiVirusProduct.ProductState)
    If Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" Then
        strproductState = "Scanning Enabled"
    ElseIf Mid(AvStatus, 2, 2) = "00" Or Mid(AvStatus, 2, 2) = "01" Then
        strproductState = "Scanning Not Enabled"
    End If

    If Mid(AvStatus, 4, 2) = "00" Then
        strdefinitionState = "AntiVirus up-to-date"
    ElseIf Mid(AvStatus, 4, 2) = "10" Then
        strdefinitionState = "AntiVirus outdated"
    End If

    objFile.Write "AntiVirus Display Name= " & strdisplayName & vbNewLine
    objFile.Write "AntiVirus Scanning Status= " & strproductState & vbNewLine
    objFile.Write "AntiVirus Definition Status= " & strdefinitionState & vbNewLine
Next
Mojoscream
  • 51
  • 1
  • 12