Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an user win32 application . That enumerates all the process details along with ProcessId. I need to print the User name along with the session ID. SessionID is enumerated using ProcessIdToSessionId() method. I want to print the User name of corresponding SessionID. This application is specially designed for WindowsXP , so the API should support WindowsXP. If anyone knows the solution please share it.

What I have tried:

DWORD dwSessionId,dwPid,dwErr;
char* Uname;
ProcessIdToSessionId(dwPid,&dwSessionId);
Posted
Updated 12-Jan-17 20:02pm

1 solution

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)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900