Re: Get Windows Logon User from inside a windows service

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



"Andreas" <Andreas@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0AFEE34B-926C-4933-B776-0E951CB7DD37@xxxxxxxxxxxxxxxx
>I am writting a windows service that records the user activity. (logon and
> logoff at the time being)
> The service is user the local system account on all PCs of the domain.
>
> Within this service i am getting the IP address of the PC and i also want
> to
> get the user name of the user that loged on to windows .
>
> I tried the code below
>
> UserName=System.Security.Principal.WindowsIdentity.GetCurrent.Name.ToString
>
> but it returns the user that the service is using (Local System Account).
>
> How can I get the user name of the user who logged on to windows?

You have two choices. Either you insinuate yourself into the logon process
or you have a helper send notifications to your service.

The latter option is easier - add a registry entry here

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

to launch an application on every login which waits for the WM_ENDSESSION to
exit. On launch or exit it sends a notification to your service.

For the former option you might want to start reading here:

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

Regards,
Will





.



Relevant Pages

  • "You have no permission to change your password"
    ... I've run into a strange problem using Windows 2000 and XP in a domain ... of the special properties like "User must change password on next logon" ... Group Policy (then again on the DC or on the local system) ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: How to force a logoff in a logon script?
    ... Windows has a registry key that governs which UI will be presented ... the unauthorized user cancels the logon dialog and goes away ... system, but complains that there was no cancel button, only an OK ...
    (microsoft.public.windows.server.scripting)
  • Re: When utilizing "Switch User" the music "NEVER" Stops!
    ... 2004 Windows MVP "Winny" Award ... Switch User, changing logons and checking the top of Zone ... >logging onto the 2nd logon and then logging off and back ... >>NEVER stopped thru any of the screens ?? ...
    (microsoft.public.windowsxp.general)
  • Re: Huh? "Login failure: the user has not been granted the requested logon type at this compute
    ... I'm a pretty experienced Windows user and programmer, ... the user has not been granted the requested logon type ... on the appropriate OU to see the Group Policy for that OU]. ... > administrators' group to the domain controller. ...
    (microsoft.public.security)
  • Re: Server 2K3 Remote Desktop Access - is this right place?
    ... All roads for that particular error of 'You do not have access to logon to ... On Windows Server 2003, launch GPEDIT.MSC from Start -> Run. ... Drill down and expand the following for Local Computer Policy: ... > Strange - when I activate the Remote Desktop Terminal from the server, ...
    (microsoft.public.win2000.advanced_server)