I am trying to list all users logged into a speceific server but am getting nowhere.
Im using the below code which i have formulated from various resources but it always returns 'not logged in'. when drilling into the oReturn object it says on alot of the items that the property could not be evaluated.
Im using the below code which i have formulated from various resources but it always returns 'not logged in'. when drilling into the oReturn object it says on alot of the items that the property could not be evaluated.
VB.NET:
Try
Dim Strcomputer As String = "IO"
With WMIConnectionOptions
.Impersonation = System.Management.ImpersonationLevel.Impersonate
.Authentication = System.Management.AuthenticationLevel.Packet
End With
WMIScope = New Management.ManagementScope("\\" & _
Strcomputer & "\root\cimv2", WMIConnectionOptions)
oq = New System.Management.ObjectQuery("SELECT UserName from Win32_ComputerSystem")
query = New ManagementObjectSearcher(WMIScope, oq)
queryCollection = query.Get()
For Each oReturn As ManagementObject In queryCollection
If Not oReturn("UserName") Is Nothing Then
MsgBox(oReturn("UserName").ToString)
Else
MsgBox("Not logged in")
End If
Next
Catch err As ManagementException
MessageBox.Show(err.Message)
End Try