SessionInfoOperationGetSessions Method |
Namespace: Xcalibur.WMI.Sessions
1// Main 2private static void Main() 3{ 4 // Make a connection to the local machine 5 const string computer = "."; 6 var managementScope = new ManagementScope($@"\\{computer}\root\cimv2", new ConnectionOptions 7 { 8 Impersonation = ImpersonationLevel.Impersonate, 9 Authentication = AuthenticationLevel.Connect 10 }); 11 managementScope.Connect(); 12 13 // Fetch data 14 var sessions = SessionInfoOperation.GetSessions(managementScope, Environment.MachineName); 15 16 // Print sessions 17 foreach (var info in sessions.Where(x => x.WindowStationName != "RDP-Tcp")) 18 { 19 Console.WriteLine($"{info.WindowStationName}, {info.UserAccount}, {info.UserName}, {info.ConnectTime}"); 20 } 21 22 // Read 23 Console.Read(); 24} 25 26/* Results: 27 * 28 * Console, CHRONOS2\josha, josha, 3/26/2018 8:44:20 PM 29 * 30 */