Looking Up the Current User and DomainLast reviewed: September 25, 1995Article ID: Q111544 |
The information in this article applies to:
SUMMARYProgram Manager displays the logged in user account and domain name in its windows title. This information can be retrieved programmatically by extracting the user SID from the current access token and then looking up the account and domain name via the LookupAccountSid() Win32 API. Below is sample code demonstrating this technique:
Sample Code
void ShowUserDomain(void){ HANDLE hProcess, hAccessToken; UCHAR InfoBuffer[1000],szAccountName[200], szDomainName[200]; PTOKEN_USER pTokenUser = (PTOKEN_USER)InfoBuffer; DWORD dwInfoBufferSize,dwAccountSize = 200, dwDomainSize = 200; SID_NAME_USE snu; hProcess = GetCurrentProcess(); OpenProcessToken(hProcess,TOKEN_READ,&hAccessToken); GetTokenInformation(hAccessToken,TokenUser,InfoBuffer, 1000, &dwInfoBufferSize); LookupAccountSid(NULL, pTokenUser->User.Sid, szAccountName, &dwAccountSize,szDomainName, &dwDomainSize, &snu); printf("%s\\%s\n",szDomainName,szAccountName);}
|
Additional reference words: 3.10 3.50
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |