0

我正在编写一个脚本来检测 Windows 机器上是否运行了防病毒解决方案。在Windows 8上运行时,我收到误报,即在运行第三方防病毒解决方案时禁用了防病毒,因为 Windows Defender 始终存在,尽管已禁用。

我可以看到第三方防病毒软件的 productState 有效且报告正确,但是我的脚本仅提取 Windows Defender 条目。

我需要保留 Windows Defender 的条目,但是如果没有安装任何其他防病毒软件,我只对 Windows Defender 感兴趣。我从命令提示符运行以下命令来检索数据,其中显示了两个单独的条目。

WMIC /Node:localhost /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct Get /Format:List

如果安装了第三方杀毒软件,我只想获取它,否则保留 Windows Defender 信息。

我试图做到这一点的方法是调用 instanceGUID 并将其与 Windows Defender GUID 进行比较,但是我得到了一些误报。有没有办法让我正确解析这些数据,理想情况下只查看第三方信息?

我包含了完整的脚本以准确显示我正在查看的内容,如果需要,我可以将其删减:

Set objWMIServiceSC = GetObject("winmgmts:\\.\root\SecurityCenter2")
Set colAVItems = objWMIServiceSC.ExecQuery("Select * from AntiVirusProduct")
For Each objAntiVirusProduct In colAVItems
    strinstanceGuid = (objAntiVirusProduct.instanceGuid)
    strWinDefGUID = "{D68DDC3A-831F-4fae-9E44-DA132C1ACF46}"
    If strinstanceGuid <> strWinDefGUID Then
        AvStatus = Hex(objAntiVirusProduct.ProductState)
        If (objAntiVirusProduct.ProductState = "393472" _
            OR Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" _
            OR Mid(AvStatus, 5, 2) = "10" Or Mid(AvStatus, 5, 2) = "11") Then
                strproductState = "ENABLED"
        Else
            strproductState = "DISABLED"
        End If
    Else
        If Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" _
            OR Mid(AvStatus, 5, 2) = "10" Or Mid(AvStatus, 5, 2) = "11" Then
                strproductState = "ENABLED"
        Else
            strproductState = "DISABLED"
        End If
    End If
    If Mid(AvStatus, 4, 2) = "00" Then
        strdefinitionState = "CURRENT"
    ElseIf Mid(AvStatus, 4, 2) = "10" Then
        strdefinitionState = "OUTDATED"
    End If
Next

重申一下,这是Windows 8的问题。

4

2 回答 2

0

我找到了解决我的问题的方法。基本上,我最终在我的 For 语句之前放置了一个 If 语句,以查看安全中心 WMI for AntiVirus 中有多少条目。如果有 0 则报告无,如果已安装 1 则读取信息,如果超过 1 则忽略 Windows Defender 并读取其余信息。我为未来的用户提供了完整的代码。

Dim objWMIServiceSC,objAntiVirusProduct,colAVItems,AvStatus

Set objWMIServiceSC = GetObject("winmgmts:\\.\root\SecurityCenter2")
Set colAVItems = objWMIServiceSC.ExecQuery("Select * from AntiVirusProduct")
If colAVItems.count = 0 Then
    strdisplayName = "No"
    errors("Acceptable AntiVirus software found ") = "NO"
ElseIf colAVItems.count = 1 Then
    For Each objAntiVirusProduct In colAVItems
        strdisplayName = (objAntiVirusProduct.displayName)
        AvStatus = Hex(objAntiVirusProduct.ProductState)
        If (objAntiVirusProduct.ProductState = "266240" _
        OR objAntiVirusProduct.ProductState = "331776" _
        OR objAntiVirusProduct.ProductState = "397568" _
        OR Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" _
        OR Mid(AvStatus, 5, 2) = "10" Or Mid(AvStatus, 5, 2) = "11") Then
            strproductState = "ENABLED"
        Else
            strproductState = "DISABLED"
            errors("Antivirus scanning is ") = "DISABLED"
        End If
        If Mid(AvStatus, 4, 2) = "00" Then
            strdefinitionState = "CURRENT"
        ElseIf Mid(AvStatus, 4, 2) = "10" Then
            strdefinitionState = "OUTDATED"
            errors("AntiVirus Definitions are ") = "OUTDATED"
        End If
    Next
ElseIf colAVItems.count > 1 Then
    For Each objAntiVirusProduct In colAVItems
        If (objAntiVirusProduct.displayName) <> "Windows Defender" Then
            strdisplayName = (objAntiVirusProduct.displayName)
            AvStatus = Hex(objAntiVirusProduct.ProductState)
            If (objAntiVirusProduct.ProductState = "393472" _
            OR objAntiVirusProduct.ProductState = "266240" _
            OR objAntiVirusProduct.ProductState = "331776" _
            OR objAntiVirusProduct.ProductState = "397568" _
            OR Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" _
            OR Mid(AvStatus, 5, 2) = "10" Or Mid(AvStatus, 5, 2) = "11") Then
                strproductState = "ENABLED"
            Else
                strproductState = "DISABLED"
                errors("Antivirus scanning is ") = "DISABLED"
            End If
                If Mid(AvStatus, 4, 2) = "00" Then
                    strdefinitionState = "CURRENT"
            ElseIf Mid(AvStatus, 4, 2) = "10" Then
                    strdefinitionState = "OUTDATED"
                    errors("AntiVirus Definitions are ") = "OUTDATED"
            End If
        End If  
    Next
End If
于 2014-07-11T17:32:34.320 回答
0

做所有这些字符串的东西看起来有点复杂。你也可以这样做:

int bitmaskUpToDate = 0x000010;
bool upToDate = number & bitmaskUpToDate == bitmaskUpToDate;
int bitmaskEnabled = 0x001000;
bool isEnabled = number & bitmaskEnabled == bitmaskEnabled;

这只是位掩码的快速演示。我没有仔细检查索引是否正确。

于 2016-01-07T18:40:11.580 回答