So the next question became: How do we uniquely identify separate instances on the same server? The quick answer was username, but that would fail if a user had multiple terminal server sessions. The better answer was to use the terminal server session id. Here's a code sample to determine your session id:
static extern bool ProcessIdToSessionId(uint dwProcessId, out uint pSessionId);
static void Main(string args)
Process _currentProcess = Process.GetCurrentProcess();
uint _processID = (uint)_currentProcess.Id;
bool _result = ProcessIdToSessionId(_processID, out _sessionID);
Console.WriteLine("ProcessIdToSessionId Result: " + _result.ToString());
Console.WriteLine("Process ID = " + _processID.ToString());
Console.WriteLine("Session ID = " + _sessionID.ToString());
- On a standalone workstation the session id is zero (0).
- The console session on a server is also zero (0).