Re: get the username of the logged on user

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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...

.



Relevant Pages

  • Re: Program will run in Terminal Session
    ... I actually WANT it to run under console. ... It's just that it ONLY runs in Terminal Session! ... >> into the server in a Terminal Service session? ... >> I used to be able to schedule this job but now it has to be run manually ...
    (microsoft.public.windows.server.general)
  • Re: Howto: ssh X11 display to Win2k
    ... >> Provided you linux machine is properly configured, ... >> if you were sitting at the console. ... > a terminal session or a terminal window. ...
    (linux.redhat.misc)
  • Re: startup scripting
    ... app when logging into the console. ... "Pegasus (MVP)" wrote in message ... I don't want it to run if logged into a terminal session. ...
    (microsoft.public.windows.server.scripting)
  • Re: Howto: ssh X11 display to Win2k
    ... > if you were sitting at the console. ... a terminal session or a terminal window. ... Fundamentalism is fundamentally wrong. ...
    (linux.redhat.misc)
  • Terminal Client PPC2002
    ... Is it possible to start a terminal session always with the same ... parmeters, so that the user has not to fill in any terms like ... "username, password" and no "connect" ... Are there any command line switches in PPC2002??? ...
    (microsoft.public.pocketpc)