How to get a list of Windows sessions?

c#, windows

Solution

I believe you'll need to use P/Invoke to retrieve this information.

The relevant APIs are documented in this MSDN page.

Problem

I am trying to find a way to get a list of Windows sessions? I need the same information as the one displayed in the Task Manager on the User tab. I need to know if the user is active or not and if s/he is logged on in the Remote Desktop session. Any idea on how to do that with C# / Windows XP Pro?

Original source