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"))
{
server.Open();
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);
}
}Read more: DevX.com
Official site: Cassia Project Home
using (ITerminalServer server = manager.GetRemoteServer("your-server-name"))
{
server.Open();
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);
}
}Read more: DevX.com
Official site: Cassia Project Home