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).




Reply With Quote