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
  1. Home
  2. General Programming
  3. C#
  4. C# - window logon events

C# - window logon events

Scheduled Pinned Locked Moved C#
sysadmincsharphelptutorial
3 Posts 3 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
    rupniceguy
    wrote on last edited by
    #1

    Can anyone help me how to retrieve the below computer event statistics on a network, i.e. The exact time computer gets logged on, logged off, locked, unlocked, remote logged on etc, also the user name who is responsible for events.. Also this should work on windows OS(XP/Server/7). If this can be done through WMI, please let me know how... Thanks!

    D S 2 Replies Last reply
    0
    • R rupniceguy

      Can anyone help me how to retrieve the below computer event statistics on a network, i.e. The exact time computer gets logged on, logged off, locked, unlocked, remote logged on etc, also the user name who is responsible for events.. Also this should work on windows OS(XP/Server/7). If this can be done through WMI, please let me know how... Thanks!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Windows doesn't track any of this information, so no, you can't do it the way you're thinking. There are no "events" for this kind of stuff. You'd have to write a client you install on every workstation you want to track to do this. Since you're supporting Windows XP, what you do will be different than it will be for Vista/7. Most of this information you can poll from the Terminal Services API, like here[^].

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      1 Reply Last reply
      0
      • R rupniceguy

        Can anyone help me how to retrieve the below computer event statistics on a network, i.e. The exact time computer gets logged on, logged off, locked, unlocked, remote logged on etc, also the user name who is responsible for events.. Also this should work on windows OS(XP/Server/7). If this can be done through WMI, please let me know how... Thanks!

        S Offline
        S Offline
        Sunil P V
        wrote on last edited by
        #3

        This can be achieved by using Win32 API. Create a method and add a Hook to get the windows notifications including logon, logoff, locked, unlocked etc. So if you are using a Winform application include this namespace

        using System.Windows.Interop;

        In the initialize method add this piece:

                    HwndSource source = HwndSource.FromHwnd(this.Handle);
                    source.AddHook(new HwndSourceHook(WndProc));
        

        where WndProc is

        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled);

        Let me know if you need a detailed implementation. I can help. Also you need to add some interop methods to access the WM_WTSSESSION_CHANGE, WTS_SESSION_UNLOCK etc.

        Sunil

        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