views:

331

answers:

1

When using .NET's Process.SessionId property or the Windows API call ProcessIdToSessionId(), can the result be relied on to be the same throughout the lifetime of the process?

i.e. If I want to use this value, do I only have to determine what it is once?

+1  A: 

No it's not safe, especially console sessions can change it's sessionid when the connection changes from RDP/remote to the physical console and vice versa or when Fast User Switching is done (Windows XP). Also it wouldn't hurt to call this API often since the SessionId is retreived from the PEB of the process.

Remko