why ImpersonateLogonUser fails ?
From: Polaris (etpolaris_at_hotmail.com)
Date: 03/25/05
- Previous message: Shenan Stanley: "Re: Spyware/Adaware infestation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Fri, 25 Mar 2005 00:18:01 -0800
Hi:
I'm testing a service on XP; within the service, I'd like to get the name of
the currently logged on user. So I choose to use the Impersonate APIs
below:
----------------------------------------------------------------
HANDLE hProc = GetCurrentProcess ();
HANDLE hToken = NULL;
OpenProcessToken (hProc, TOKEN_IMPERSONATE|TOKEN_QUERY, &hToken);
ImpersonateLoggedOnUser (hToken);
wchar_t login [MAX_PATH];
DWORD len = MAX_PATH;
GetUserName (login, (PULONG)&len);
--------------------------------------------------------------
To make the code above simple to read, I did not copy the error checking
here. The code above fails at ImpersonateLoggedOnUser and GetLastError is 5
(Access is Denied).
Any thought is welcome!
Thanks in Advance.
Polaris
- Previous message: Shenan Stanley: "Re: Spyware/Adaware infestation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]