Re: get the username of the logged on user
- From: "Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx>
- Date: Fri, 5 Oct 2007 11:54:16 +0900
WTSGetActiveConsoleSessionId will get you the terminal session number of the current console. If someone is logged in at the console then this will be their session; otherwise this session will be owned by winlogin (waiting for someone to log in).
WTSQuerySessionInformationW, when called with appropriate parameters, can get the username of whoever is logged into a terminal session (including the console, as above). Beware that WTSQuerySessionInformationA is broken. If your application is ANSI then you have to call the Unicode version WTSQuerySessionInformationW and then call WideCharToMultiByte.
"Rohit Kumar" <RohitKumar@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:A9A1FFE7-E32F-4B88-8512-8C0B1488CD68@xxxxxxxxxxxxxxxx
I am creating a windows service which is running under Localsystem account.
How can i find out the username of the currently logged in user.
GetUserName() function returns "SYSTEM". Even the GetTempPath() function
returns the path of systems temp directory. And every access to
HKEY_CURRENT_USER registry key gives me wrong information as the current user
in such case is .Default
Can anyone please tell me a way to find out the name of the logged in
windows user??? The service has to run in system context so i cant change it.
Thanks in Advance...
.
- Prev by Date: Re: PostThreadMessage and Lost Messages
- Next by Date: Re: This calculation is just wrong / computer can't count!
- Previous by thread: Re: get the username of the logged on user
- Next by thread: CTabCtrl as sibling of CMDIFrameWnd::m_hWndMDIClient
- Index(es):
Relevant Pages
|