Finding Current/Active Session ID

A

Ahmed Perlom

Hi all,

How can I know if the session ID that a certain process is running on is
actually the active session that he consol is connected to. I can get the
session id of a process by



Process P = Process.GetCurrentProcess();

And then check P.SessionID property.



Anyone has an idea?



Thanks
 
S

Siva M

If you are asking whether the process is running under Terminal Services or
local console then: If the SessionID is not 0 then it is running under TS.

HTH

Hi all,

How can I know if the session ID that a certain process is running on is
actually the active session that he consol is connected to. I can get the
session id of a process by



Process P = Process.GetCurrentProcess();

And then check P.SessionID property.



Anyone has an idea?



Thanks
 
A

Ahmed Perlom

Hi, thanks for the reply. Actually, I want to know if a certain process is
running on the session (desktop) that has the keyboard and mouse. I
understand that there might be more than one user session (using the fast
user switch capability on WinXP) but I want to check for the session with
the user currently interacting with the computer.



I found the function "WTSGetActiveConsoleSessionId" from the terminal
services, but it's an unmanaged code, and I was wondering if there is any
..NET managed way to get the same info.



Thanks for the help,
 
S

Siva M

Hello,

Its easy to use the same API from .NET
http://www.pinvoke.net/default.aspx/wtsapi32.WTSQuerySessionInformation

Hi, thanks for the reply. Actually, I want to know if a certain process is
running on the session (desktop) that has the keyboard and mouse. I
understand that there might be more than one user session (using the fast
user switch capability on WinXP) but I want to check for the session with
the user currently interacting with the computer.



I found the function "WTSGetActiveConsoleSessionId" from the terminal
services, but it's an unmanaged code, and I was wondering if there is any
..NET managed way to get the same info.



Thanks for the help,
 
A

Ahmed Perlom

Thanks for the reply. I tried the PInvoke solution and it works. The
problem it is unmanaged code that need to run in full-trust mode. I was
looking for a managed code solution that would run in a lower privilege.

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top