Identifying remote users using WMI
Hi - I have some VB code that I'm trying to translate to c#. The code has a few WMI calls in it, and I'm stuck. Specifically, my VB code has the following:
'identify remote sessions
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")
'loop through results and get logged on userid
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
'look for match with current user (Session["UserEID"] as id'd by
'Windows Authentication in Global.asax
If objItem.Name = Session["UserEID"] Then
etc etc
The c# equivalent to get remote sessions is
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_LogonSession WHERE LogonType = 10");
foreach (ManagementObject queryObj in searcher.Get())
etc etc
but then how do I drill down in my remote sessions to find the Name property from the Win32_LoggedOnUser class?
Of course, if anyone knows of another way to do this, that would be fine, too, doesn't have to be via WMI.
Thanks!