|
-
Aug 4th, 2006, 03:03 PM
#1
Thread Starter
Junior Member
[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:
Private Function PullWMI(ByVal Target As String, ByVal Container As String, ByVal Value As String) As String
'target = IP address of target system
'Container = WIN32_XXXXXX
'Value = desired value from container
'WMI delare
Dim Rtrn As String = ""
Try
Dim query As New SelectQuery(Container)
Dim ms As New System.Management.ManagementScope("\\" & Target & "\root\cimv2")
ms.Connect()
If ms.IsConnected = False Then
Exit Try
End If
Dim searcher As New ManagementObjectSearcher(ms, query)
Dim results As ManagementObjectCollection = searcher.Get
Dim enumerator As ManagementObjectCollection.ManagementObjectEnumerator = results.GetEnumerator
enumerator.MoveNext()
Dim properties As ManagementObject = enumerator.Current
'pass var delare/set
If properties(Value) <> Nothing Then ' keeps returning as Nothing...???
Rtrn = properties(Value).ToString
Else
Rtrn = ""
End If
searcher.Dispose()
results.Dispose()
enumerator.Dispose()
properties.Dispose()
Catch ex As Exception
Rtrn = ""
ErrMsg = ex.Message.ToString
HasErr = True
Exit Try
End Try
'return var
Return Rtrn
End Function
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.
-
Aug 4th, 2006, 04:31 PM
#2
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...
-
Aug 4th, 2006, 04:40 PM
#3
Thread Starter
Junior Member
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:
Private Function PullWMI(ByVal Target As String, ByVal Container As String, ByVal Value As String) As String
'WMI delare
Dim Rtrn As String = ""
Try
Dim query As New SelectQuery(Container)
Dim co As New System.Management.ConnectionOptions
co.Authentication = AuthenticationLevel.Packet
co.EnablePrivileges = True
co.Impersonation = ImpersonationLevel.Impersonate
Dim ms As New System.Management.ManagementScope("\\" & Target & "\root\cimv2", co)
ms.Connect()
If ms.IsConnected = False Then
Exit Try
End If
Dim searcher As New ManagementObjectSearcher(ms, query)
Dim results As ManagementObjectCollection = searcher.Get
Dim enumerator As ManagementObjectCollection.ManagementObjectEnumerator = results.GetEnumerator
enumerator.MoveNext()
Dim properties As ManagementObject = enumerator.Current
'pass var delare/set
If properties(Value) <> Nothing Then
Rtrn = properties(Value).ToString
Else
Rtrn = ""
End If
searcher.Dispose()
results.Dispose()
enumerator.Dispose()
properties.Dispose()
Catch ex As Exception
Rtrn = ""
ErrMsg = ex.Message.ToString
HasErr = True
Exit Try
End Try
'return var
Return Rtrn
End Function
-
Aug 4th, 2006, 04:45 PM
#4
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...
-
Aug 4th, 2006, 04:54 PM
#5
Thread Starter
Junior Member
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...
-
Aug 4th, 2006, 05:24 PM
#6
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....
-
Aug 4th, 2006, 05:33 PM
#7
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|