Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking AV up to date in server 2008

Status
Not open for further replies.

Hfnet

IS-IT--Management
Dec 31, 2003
369
GB
I have the following code which works in XP, Vista and 7 which I took from WMI. It does not work in SBS 2008 however. I am assuming security center is not installed, but the WMI does return a value when run as a vbs, so I wondered if anyone could shed any light on how to return AV up to date in 2008 and R2?
Code:
AVUpToDate = False
        Dim sCPath As String = ""
        Try
            Select Case Environment.OSVersion.Version.Major
                Case "6"
                    sCPath = "\root\SecurityCenter2"
                Case "5"
                    sCPath = "\root\SecurityCenter"
            End Select

            Dim computer As String = "." 'Environment.MachineName
            Dim wmipath As String = "\\" & computer & sCPath
            Dim query As String = "SELECT * FROM AntivirusProduct"

            Dim searcher As New ManagementObjectSearcher(wmipath, query)
            Dim results As ManagementObjectCollection = searcher.[Get]()

            'do something with result
            For Each result As ManagementObject In results
                Me.lblAVVersion.Text = result("displayName").ToString()
                Me.lblAVVersion.Visible = True
                For Each result1 In results
                    If result("productState") >= 266240 Then
                        AVUpToDate = True
                    Else
                        AVUpToDate = False
                    End If
                Next
            Next
        Catch
            If Err.Number <> 0 Then
                Me.lblAVVersion.Text = "Unable to check"
                Me.lblAVVersion.ForeColor = Color.Red
                Me.lblAVVersion.Visible = True
            End If

        End Try
 
I managed to figure it out. For anyone interested, here is my code:

Code:
        Dim strComputer = "."
        Dim upd_thresh = 4
        Dim wmiLocator = CreateObject("WbemScripting.SWbemLocator")
        Dim wmiNameSpace = wmiLocator.ConnectServer(strComputer, "root\default")
        Dim oReg = wmiNameSpace.Get("StdRegProv")

        Dim regkey As RegistryKey
        Dim keyValue As String, keyValue1 As String
        If Is64BitOperatingSystem() Then
            keyValue = "SOFTWARE\WOW6432Node\Sophos\SAVService\Application"
            keyValue1 = "SOFTWARE\WOW6432Node\Sophos\AutoUpdate\UpdateStatus"
        Else
            keyValue = "SOFTWARE\Sophos\SAVService\Application"
            keyValue1 = "SOFTWARE\Sophos\AutoUpdate\UpdateStatus"
        End If
        
        regkey = Registry.LocalMachine.OpenSubKey(keyValue)
        If Not (regkey Is Nothing) Then
            Dim strTemp = regkey.GetValue("ProductCode")

            If strTemp <> "" Then
                'we have a sophos key, assume that sophos is installed so get the details.
                Me.lblAVVersion.Text = "Sophos Anti-Virus"
                Me.lblAVVersion.Visible = True
                
                Dim regkey1 As RegistryKey

                regkey1 = Registry.LocalMachine.OpenSubKey(keyValue1)
                If Not (regkey1 Is Nothing) Then
                    Dim strTemp1 = regkey1.GetValue("LastUpdateTime")
                    Dim av_lastupd = DateAdd("s", strTemp1, "01/01/1970 00:00:00")

                    Dim strTemp2 = regkey.GetValue("Result")
                    Dim av_lastupd_status = strTemp2

                    ' we will say it is up to date if the last update status was 0 and it was less than upd_thresh hours ago

                    If ((av_lastupd_status = 0) And (DateDiff("h", av_lastupd, Now)) < upd_thresh) Then

                        W2008AV = True
                    Else
                        W2008AV = False
                    End If

                End If
            End If
        Else
            Me.lblAVVersion.Text = "Unable to locate AntiVirus automatically"
            Me.lblAVVersion.Visible = True
        End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top