Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: .NET
Expertise: Intermediate
Apr 7, 2010

Use the Cassia .NET Library to Detect Users Connected to Windows Server

To programmatically detect the users connected to Windows Server, you have to use PInvoke to call the Windows Terminal Services API. Alternatively, you can use a .NET library called Cassia, which was created exclusively for this purpose. Cassia provides a wrapper around the Windows Terminal Services API.

The following code snippet gives you an idea of how to use Cassia (extracted from the Cassia Project Home):

ITerminalServicesManager manager = new TerminalServicesManager();
using (ITerminalServer server = manager.GetRemoteServer("your-server-name"))
    foreach (ITerminalServicesSession session in server.GetSessions())
        Console.WriteLine("Session ID: " + session.SessionId);
        Console.WriteLine("User: " + session.UserAccount);
        Console.WriteLine("State: " + session.ConnectionState);
        Console.WriteLine("Logon Time: " + session.LoginTime);
Deepak Choudhari
Thanks for your registration, follow us on our social networks to keep up-to-date