Detecting username from process id

Ho, I can get the name of the user account that started the process with the given id. Is there an api function for this?

I am using windows, C ++.

+5
source share
1 answer

There is no API function that does this directly, however you can combine multiple API calls for this. Of course, your program will have to satisfy any ACLs that apply to the process that interests you.

First, given the process id, you need to open the process descriptor. You can use OpenProcessfor this, requesting access rights PROCESS_QUERY_INFORMATION.

, OpenProcessToken, TOKEN_QUERY.

, GetTokenInformation, TokenUser, , SID. SID , LookupAccountSid.

CloseHandle , , .

+12

All Articles