tags:

views:

575

answers:

3

Hello all,

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?

Thanks, Martin

+1  A: 

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

The relevant APIs are documented in this MSDN page.

Reed Copsey
A: 

As a starting point you can get a list of users logged on by running the command

qwinsta

From the command prompt.

This will give output like

C:\WINDOWS\system32>qwinsta
SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
>console           me                       0  Active  wdcon
rdp-tcp                                 65536  Listen  rdpwd

and will list any remote sessions.

pjp
A: 

Use LsaEnumerateLogonSessions via P/Invoke. You'll also need LsaFreeReturnBuffer to cleanup after enumerating.

Kevin Montrose