Jac0b
Jac0b

Reputation: 173

How to get username/SID from session id in Windows?

I Want to get the username or SID from a session id value, how can I do that working from Window XP using the WinAPI?

Upvotes: 3

Views: 6530

Answers (2)

c00000fd
c00000fd

Reputation: 22327

If you need this from a local system service then you can call WTSQueryUserToken to get user token from session ID, and then use method similar to this one to retrieve a user SID (or user/domain name) using GetTokenInformation API.

Upvotes: 5

Mitch
Mitch

Reputation: 22311

You can use the WTSQuerySessionInformation function to get the Username and Domain (WTSUserName and WTSDomainName from WTS_INFO_CLASS).

This function is available as far back as Windows 2000.

Upvotes: 8

Related Questions