Results 1 to 7 of 7

Thread: [2005|2.0]WMI output problems...

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    27

    [2005|2.0]WMI output problems...

    I am working on an app that will pull WMI data from all systems currently on the subnet, I have a class in place that correctly collects a list of currently active IP's and I am then feeding those through this function to get the desired data. However some systems correctly report data while about half of the systems return nothing even though WMI says it connects sucessfully. Can anyone take a look and see if there is something I am doing wrong?

    VB Code:
    1. Private Function PullWMI(ByVal Target As String, ByVal Container As String, ByVal Value As String) As String
    2. 'target = IP address of target system
    3. 'Container = WIN32_XXXXXX
    4. 'Value = desired value from container
    5.         'WMI delare
    6.         Dim Rtrn As String = ""
    7.         Try
    8.             Dim query As New SelectQuery(Container)
    9.             Dim ms As New System.Management.ManagementScope("\\" & Target & "\root\cimv2")
    10.             ms.Connect()
    11.             If ms.IsConnected = False Then
    12.                 Exit Try
    13.             End If
    14.             Dim searcher As New ManagementObjectSearcher(ms, query)
    15.             Dim results As ManagementObjectCollection = searcher.Get
    16.             Dim enumerator As ManagementObjectCollection.ManagementObjectEnumerator = results.GetEnumerator
    17.             enumerator.MoveNext()
    18.             Dim properties As ManagementObject = enumerator.Current
    19.             'pass var delare/set
    20.             If properties(Value) <> Nothing Then ' keeps returning as Nothing...???
    21.                 Rtrn = properties(Value).ToString
    22.             Else
    23.                 Rtrn = ""
    24.             End If
    25.             searcher.Dispose()
    26.             results.Dispose()
    27.             enumerator.Dispose()
    28.             properties.Dispose()
    29.         Catch ex As Exception
    30.             Rtrn = ""
    31.             ErrMsg = ex.Message.ToString
    32.             HasErr = True
    33.             Exit Try
    34.         End Try
    35.         'return var
    36.         Return Rtrn
    37.     End Function
    38. End Class


    As you can see in the code if ms.connect fails it would not enter the rest of the code, on top of that this is running inside a thread and it it takes over 500ms it will return an error (yes I have tried it otside a thread with the same results).
    Last edited by Thildemar; Aug 4th, 2006 at 03:16 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width