Discussion:
Get handle to user's token
(too old to reply)
Roshan
2007-06-02 05:15:21 UTC
Permalink
Hi,

I am new to windows programming and am trying to find the the easiest
way to get a handle to the current user's token, without using
LsaLogonUser? My code is already running in that user's context and I
donot have the user's password.

Would appreciate any help,

Thanks,
RB
Kellie Fitton
2007-06-02 06:27:31 UTC
Permalink
Post by Roshan
Hi,
I am new to windows programming and am trying to find the the easiest
way to get a handle to the current user's token, without using
LsaLogonUser? My code is already running in that user's context and I
donot have the user's password.
Would appreciate any help,
Thanks,
RB
Hi,

You can use the following APIs to search for a SID in an access token:

GetCurrentProcess()
OpenProcessToken()
GlobalAlloc()
GetTokenInformation()
AllocateAndInitializeSid()
LookupAccountSid()
FreeSid()
GlobalFree()

Now... each user gets an access token at logon, when the user
launches a process, the system associates the user access token
to that process, unless you use the following APIs:

LogonUserEx()
CreateProcessAsUser()

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getcurrentprocess.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/openprocesstoken.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/globalalloc.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/gettokeninformation.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/allocateandinitializesid.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/lookupaccountsid.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/freesid.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/globalfree.asp

Kellie.

Continue reading on narkive:
Loading...