Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. When did user logon

When did user logon

Scheduled Pinned Locked Moved C#
securityquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RickZ
    wrote on last edited by
    #1

    I have a program that runs as a service and needs to know when any user has successfully logged in. Using the SystemInformation.UserName shows that 'this' process was stated by the 'SYSTEM'. I have been forewarned about touching the security events by the end users IT management, so looking for a valid logon event with the current setting are out of the question. Any ideas would be very much appreciated. Rick

    H 1 Reply Last reply
    0
    • R RickZ

      I have a program that runs as a service and needs to know when any user has successfully logged in. Using the SystemInformation.UserName shows that 'this' process was stated by the 'SYSTEM'. I have been forewarned about touching the security events by the end users IT management, so looking for a valid logon event with the current setting are out of the question. Any ideas would be very much appreciated. Rick

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      A service always runs as the user under which it's configured to run. If your service is configured to run as SYSTEM, then it will always run as SYSTEM when the service is started (at startup if configured as such, which is the default behavior). Many services will implement APIs that impersonate users but still can only run as a certain account (like SYSTEM). If you want to moniter when other users log in (since your service is continually running despites whether or not someone's logged in), then you need to monitor system events. The .NET FCL (Framework Class Library) exposes no such APIs, so you'll have to use unmanaged code through COM interop or P/Invoke. If you're limited from checking security events, then you could use WMI and handle an event query for the Win32_LogonSession WMI class. The details are buried in Microsoft implementations and all you have to do is register to receive an event when something changes. See the class documentation for the System.Management namespace and see MSDN Magazine[^] for several good articles (including links to more information and a good WMI plugin for VS.NET's Server Explorer (beta for 2002, released for 2003 - but both work good).

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups