mellomel70
Member
- Joined
- May 10, 2010
- Messages
- 8
- Programming Experience
- 10+
Hi - I'm writing a script that will identify remote logons. I've done this before successfully with WMI, but I need to use WMI.Net this time around. For why, see WMI calls ignored outside of VisualStudio. Anyway, I have code that works, but I need to output some data, specifically a network user ID, and I'm not sure what I need to do in WMI.Net to accomplish this. Here's my old WMI code (objItem.Name is what I need to get at):
Here's the WMI.Net version:
In the .Net world objItem doesn't have a Name property. Where can I go to find what the properties of this object are in WMI.Net and which one I should be using to get the user's network ID?
Thanks!
VB.NET:
Dim strComputer As String = "."
Dim objWMIService As Object = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Dim colSessions As Object = objWMIService.ExecQuery("Select * from Win32_LogonSession Where LogonType = 10")
Dim objSession As Object
For Each objSession In colSessions
Dim colList As Object
colList = objWMIService.ExecQuery("Associators of " & "{Win32_LogonSession.LogonId=" & objSession.LogonId & "} " & "Where AssocClass=Win32_LoggedOnUser Role=Dependent")
Dim objItem As Object
For Each objItem In colList
If objItem.Name = Session("UserEID") Then
'Do Something
End If
Next
Here's the WMI.Net version:
VB.NET:
Dim query As ObjectQuery
query = New ObjectQuery("Select * from Win32_LogonSession Where LogonType = 10")
Dim searcher As ManagementObjectSearcher
searcher = New ManagementObjectSearcher(query)
Dim queryCollection1 As ManagementObjectCollection = searcher.Get()
' Get the resulting collection and loop through it
Dim mo As ManagementBaseObject
For Each mo In queryCollection1
query = New ObjectQuery("Associators of " & "{Win32_LogonSession.LogonId=" & mo("LogonId") & "} " & "Where AssocClass=Win32_LoggedOnUser Role=Dependent")
Next
Dim searcher2 = New ManagementObjectSearcher(query)
For Each objItem As ManagementObject In searcher2.Get()
If objItem.Name = Session("UserEID") Then
'Do Something
End If
Next
In the .Net world objItem doesn't have a Name property. Where can I go to find what the properties of this object are in WMI.Net and which one I should be using to get the user's network ID?
Thanks!