Alfonso Gunn
Alfonso Gunn

Reputation:

Retrieving Terminal Services Session ID In .NET?

Can anyone please help me discover the .NET equivalent of the following C++ code:

DWORD session_id;
ProcessIdToSessionId(GetCurrentProcessId(), &session_id);

I'm trying to find the current terminal services session number to uniquely name a named pipe that two programs inside the same session are using to communicate with each other. But the only information I can find when searching for .NET sessions is web stuff.

Thanks.

Upvotes: 6

Views: 7365

Answers (1)

Noldorin
Noldorin

Reputation: 147240

Indeed, this functionality is provided completely within the BCL (System.Diagnostics namespace):

var sessionId = Process.GetCurrentProcess().SessionId;

See the SessionId property on MSDN for more info.

Upvotes: 16

Related Questions