Results 1 to 7 of 7

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

  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.

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

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

    I would imagine it might have to do with some sort of permissions issue, although not too sure. There is an overloaded method of the managementscope object that accepts a ConnectionOptions parameter, which gives you options like Authentication, Authority, EnabledPriveleges, and more in order to set for the connection. Perhaps the machines that pull no info require some sort of extra priveleges in order to run properly, which can be set by passing in a ConnectionOptions parameter for the ManagementScope object...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    27

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

    Tried that with the values set to what I think they should be...still no luck code is now as follows:


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

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

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

    Well I also see options for Username and Password in the ConnectionOptions object that might need to be set...

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    27

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

    from reading the MSDN documentation It looks like username and password are only for overriding the user that is currently logged in, as I am logged in as a full administator this should not be the issue...But I shall try it and let you know.

    EDIT: Yup, same results except now I get a message about not being able to use credentials for local system so that one no longer works =) Other than that the same few show up and the ones that kept returning nothing are still returning nothing...

  6. #6
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

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

    Well I have never used it myself, just was mentioning that it was there. I am not sure why this is ocurring, some other person from a thread in the past had mentioned how the same kind of thing was ocurring, he had a few machines that wouldn't pull any kind of info, but he didn't ever reply back if he fixed it or not.

    I'm wondering if theres anyway you can try to query information locally on the machines that are having problems? Just to see if you can in fact query WMI info fine locally on the machine. The MySystemSpy in my sig is a small program you can test it with if you wish, it just uses WMI in order to pull all the hardware information on the system depending on the hardware class you wish to try....

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    27

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

    I know that some of them at least work as I am working to convert a locally run app to a network one. The old one resides on a local machine and loads its data to a text file on the server. Some of the systems that I can not get info from now did work just fine on the old app, unfortunately there is little way to test them all... Ill think about it over the weekend and see if I can come up with anything, would appriciate it if anyone out there could do the same...Ill check back here monday =)

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