Imports System.Management

Public Class RemoteWMI
    Dim co As ConnectionOptions
    Dim ms As System.Management.ManagementScope

    Public Sub New(ByVal PCName As String)
        co = New ConnectionOptions
        ms = New System.Management.ManagementScope("\\" & PCName & "\root\cimv2", co)
    End Sub
    Public Sub New(ByVal PCName As String, ByVal UserID As String, ByVal Password As String)
        co = New ConnectionOptions
        co.Username = UserID
        co.Password = Password
        ms = New System.Management.ManagementScope("\\" & PCName & "\root\cimv2", co)
    End Sub

    Public Function GetWmiValue(ByVal WMIClass As String, ByVal WMIProperty As String) As ArrayList
        'Query remote computer across the connection
        Dim oq As New System.Management.ObjectQuery("SELECT " & WMIProperty & " FROM " & WMIClass)
        Dim query1 As New ManagementObjectSearcher(ms, oq)
        Dim queryCollection1 As ManagementObjectCollection = query1.Get()

        Dim WMIProp() As String = WMIProperty.Split(",")
        Dim MyAL As New ArrayList
        For Each mo As ManagementObject In queryCollection1
            Dim tmp As String = ""
            For i As Integer = 0 To WMIProp.Length - 1
                If UCase(WMIProp(i)) = "IPADDRESS" Then
                    tmp += Join(mo.Item(WMIProp(i)), ".") & ","
                Else
                    Try
                        tmp += mo.Item(WMIProp(i)).ToString & ","
                    Catch
                        tmp += ","
                    End Try
                End If
            Next
            tmp = tmp.TrimEnd(",")
            MyAL.Add(tmp)
        Next
        Return MyAL
    End Function

    Public Sub Dispose()
        ms = Nothing
        co = Nothing
    End Sub

End Class