Feedback

VB - Informationen über AV Produkt (Remote)

Veröffentlicht von am 12/27/2006
(3 Bewertungen)
Unter Umständen benötigen Sie in Ihrer Applikation Informationen über den installierten Virenscanner und dessen Verhalten (Online Scan ...)

Die nachfolgende Funktion lieferte diese Infos (Voraussetzung: Win XP min, SP2) von einer Remotemaschine in einer ACTIVE DIRECTORY DOMAIN.

Das nachfolgende Beispiel benötigt:

Ein Listview Steuerelement (View: Deteils) mit 2 Spalten, 1 Button


Public Function RemoteWin32_AVP(ByVal strComputer As String, ByVal strUser As String, _
                                    ByVal strPwd As String, Optional ByVal strDomain As String = "Default") As String


        Dim options As ConnectionOptions
        options = New ConnectionOptions()

        If strDomain = "Default" Then strDomain = strComputer


        options.Username = strDomain & "\" & strUser
        options.Password = strPwd
        'options.Authority = "kerberos:" & strDomain


        Dim scope As ManagementScope
        scope = New ManagementScope( _
            "\\" & strComputer & "\root\SecurityCenter", options)

        Try
            scope.Connect()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error while Connecting", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Return "Error"
            Exit Function
        End Try


        Dim query As ObjectQuery
        query = New ObjectQuery( _
            "SELECT * from AntiVirusProduct")
        Dim searcher As ManagementObjectSearcher
        searcher = New ManagementObjectSearcher(scope, query)

        Dim queryCollection As ManagementObjectCollection
        queryCollection = searcher.Get()

        Dim m As ManagementObject
        Dim str As String = String.Empty

        For Each m In queryCollection

            'Dim lvi As New ListViewItem
            'lvi.Text = m("DisplayName").ToString

            Try
                Me.ListView1.Items.Add("Name")
                Me.ListView1.Items(0).SubItems.Add(m("DisplayName").ToString)

            Catch ex As Exception
                Me.ListView1.Items.Add("Name")
                Me.ListView1.Items(0).SubItems.Add(m("n.a."))

            End Try

            Try
                Me.ListView1.Items.Add("Version")
                Me.ListView1.Items(1).SubItems.Add(m("VersionNumber").ToString)

            Catch ex As Exception
                Me.ListView1.Items.Add("Version")
                Me.ListView1.Items(1).SubItems.Add(m("n.a."))

            End Try

            Try
                Me.ListView1.Items.Add("Company")
                Me.ListView1.Items(2).SubItems.Add(m("CompanyName").ToString)

            Catch ex As Exception
                Me.ListView1.Items.Add("Company")
                Me.ListView1.Items(2).SubItems.Add(m("n.a."))

            End Try

            Try
                Me.ListView1.Items.Add("Product Upto date")
                Me.ListView1.Items(3).SubItems.Add(m("productUptoDate").ToString)

            Catch ex As Exception
                Me.ListView1.Items.Add("Product Upto date")
                Me.ListView1.Items(3).SubItems.Add(m("n.a."))

            End Try


            Try
                Me.ListView1.Items.Add("On Access Scanning Enabled")
                Me.ListView1.Items(4).SubItems.Add(m("onAccessScanningEnabled").ToString)

            Catch ex As Exception
                Me.ListView1.Items.Add("On Access Scanning Enabled")
                Me.ListView1.Items(4).SubItems.Add(m("n.a."))

            End Try

            Application.DoEvents()
        Next


        For Each locColumn As ColumnHeader In Me.ListView1.Columns
            locColumn.Width = -2
        Next

        Return "OK"

End Function


'Aufruf

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click

        RemoteWin32_AVP("Computer1", "User1", "PaSSwOrD1", "Domaine.com")

End Sub
Abgelegt unter ADS, AV.

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!