How to detect when a user logs in using .NET (C #)?

I need to detect the login time of a user connected to the server by remote desktop or console in C #. I tried to find a property in WMI classes, but I did not find it. Thanks again!

+3
source share
1 answer

Check out cassia , the .NET Terminal Services library.

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);
    }
}

You can also use P / Invoke to directly access the Windows Terminal Services API , but cassia wraps it for you.

+2
source

Source: https://habr.com/ru/post/1716104/


All Articles