0

我正在尝试从 Windows 7 或 8 中的 Windows 安全中心 2 获取 AntiVirus 的状态。我可以从“objAntiVirusProduct.displayName”中提取数据并显示信息,但是我似乎无法使 Hex 正常工作. 这就是我现在所拥有的。

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 

我错过了什么?

编辑:我被要求提供一些我的输出示例。

我收到的是:

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

我期待的是:

AntiVirus Display Name= Norton Endpoint Protection
AntiVirus Scanning Status= (SCANNING STATUS)
AntiVirus Definition Status= (AV UPDATE STATUS)
4

1 回答 1

0

找出我的问题是什么,我实际上是在加倍完成任务所需的工作量。我所做的是我删除了第 8 行和第 9 行,这让一切正常工作。我还检查并删除了不再需要的变量,并将其美化了一些。

我完成的代码如下所示:

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
于 2014-06-19T19:40:41.317 回答