Why would you want to use the Session ID when you have the Process ID? Use that to get the user name.
Using the process ID returned by
ProcessIdToSessionId
might not work as already mentioned in my previous answer
C++ code to print all process with session ID[
^]:
Quote:
Remarks
If the calling process is not running in a Terminal Services environment, the value returned in pSessionId is zero
The above is from an old SDK and applies to Windows versions up to XP. Assuming that you are not executing your XP application in a Terminal Service, the Session ID will be always zero.
To get the name from the Process ID see these functions (or serach the web for example code):
OpenProcessToken function (Windows)[
^]
GetTokenInformation function (Windows)[
^] (with class
TokenOwner
to get the user's
SID
)
LookupAccountSid function (Windows)[
^]