How to get the multiple user login session details from windows server 2012?

405 Views Asked by At

I'm planning to develop a window form application to collect the user login session details.

Scenario: "Consider 10 systems connected with windows server 2012. I want collect the log in, log out and lock details of 10 user systems from my server(windows server 2012)."

Is it possible get those details using c#?

1

There are 1 best solutions below

0
On

Yes, it's possible. You need to analyze Logon\Logoff event ids of Security event log.

        EventLog myLog = new EventLog();
        myLog.Log = "Security";
        foreach (EventLogEntry entry in myLog.Entries)
        {
            if (entry.InstanceId == 4648 || entry.InstanceId == 4654)
                Console.WriteLine("\tEntry: " + entry.Message);
        }
        Console.ReadLine(); 

After you filter logon\logoff events, you can link them pairwise by LogonID field.