How to get the user name of a process when Vista UAC open?

S

Steff

I can get the user name of a process in Windows XP by following code:
GetCurrentProcess();
GetSecurityInfo(handle,SE_KERNEL_OBJECT,OWNER_SECURITY_INFORMATION,&pSidOwner,NULL,NULL,NULL,&pSD);LookupAccountSid(NULL, pSidOwner, lpName,&cchName,lpReferencedDomainName,&cchReferencedDomainName, &peUse);But I failed in Vista when UAC opened:if the user of the process is in administrators group, and it is run asadministrator, the code above return the name (in lpName): "administrators"instead of the real user name.Who can help me?
 
J

Jon

Steff said:
I can get the user name of a process in Windows XP by following code:
GetCurrentProcess();
GetSecurityInfo(handle,SE_KERNEL_OBJECT,OWNER_SECURITY_INFORMATION,&pSidOwner,NULL,NULL,NULL,&pSD);LookupAccountSid(NULL,
pSidOwner,
lpName,&cchName,lpReferencedDomainName,&cchReferencedDomainName,
&peUse);But I failed in Vista when UAC opened:if the user of the process
is in administrators group, and it is run asadministrator, the code above
return the name (in lpName): "administrators"instead of the real user
name.Who can help me?


Sounds like you need to use 'impersonation'
 
S

Steff

I solved my question: should be use:
BOOL GetTokenInformation(
HANDLE TokenHandle,
TOKEN_INFORMATION_CLASS TokenInformationClass,
LPVOID TokenInformation,
DWORD TokenInformationLength,
PDWORD ReturnLength
);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top