Click or drag to resize

SessionInfoOperationGetSessions Method

Gets a list of Sessions currently present on the host.

Namespace:  Xcalibur.WMI.Sessions
Assembly:  Xcalibur.WMI (in Xcalibur.WMI.dll) Version: 3.0.0.0 (3.0.1.0)
Syntax
public static ISessionInfo[] GetSessions(
	ManagementScope ms,
	string machine
)

Parameters

ms
Type: System.ManagementManagementScope
The management scope.
machine
Type: SystemString
The computer name.

Return Value

Type: ISessionInfo
Examples
C#
 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 */
See Also