Handle the Windows Lock Desktop event/message?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brandon@bc3tech.net

    #1

    Handle the Windows Lock Desktop event/message?

    Anybody out there know how I could go about handling, in a systray'd
    app, the windows message that the desktop is going to be locked? This
    way the application can react whenever the Win+L or Ctrl+Alt+Del+L is
    used to lock the computer. I realize this will probably involve some
    Windows API work, and am aware of the LockWorkStation inside the
    User32.dll which causes the locking of the computer, but don't know
    where to start to find out how to get that message from the API when my
    form does NOT have focus. I imagine it will involve a Hook to the OS
    somehow, but don't want to just hook the Win+L combo or just the
    Ctrl+Alt+Del+L or any other way it locks, so would rather grab the
    event.

    Thanks!

  • Chris Malone

    #2
    Re: Handle the Windows Lock Desktop event/message?


    An option would be to

    a. Write your own GINA
    b. Use the GINA hooks in the Platform SDK

    Have a look at:
    http://msdn.microsoft.com/msdnmag/is...ecurityBriefs/

    Maybe that will get you going in the right direction

    Comment

    • Mattias Sjögren

      #3
      Re: Handle the Windows Lock Desktop event/message?

      [color=blue]
      >Anybody out there know how I could go about handling, in a systray'd
      >app, the windows message that the desktop is going to be locked?[/color]

      Check out the WTSRegisterSess ionNotification API.


      Mattias

      --
      Mattias Sjögren [C# MVP] mattias @ mvps.org
      http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
      Please reply only to the newsgroup.

      Comment

      • Willy Denoyette [MVP]

        #4
        Re: Handle the Windows Lock Desktop event/message?


        <brandon@bc3tec h.net> wrote in message
        news:1137196642 .555343.109980@ g49g2000cwa.goo glegroups.com.. .
        | Anybody out there know how I could go about handling, in a systray'd
        | app, the windows message that the desktop is going to be locked? This
        | way the application can react whenever the Win+L or Ctrl+Alt+Del+L is
        | used to lock the computer. I realize this will probably involve some
        | Windows API work, and am aware of the LockWorkStation inside the
        | User32.dll which causes the locking of the computer, but don't know
        | where to start to find out how to get that message from the API when my
        | form does NOT have focus. I imagine it will involve a Hook to the OS
        | somehow, but don't want to just hook the Win+L combo or just the
        | Ctrl+Alt+Del+L or any other way it locks, so would rather grab the
        | event.
        |
        | Thanks!
        |

        When running on W2K or higher using framework v2.0, you could set-up a
        listener for SystemEvents notifications.
        Please check the Microsoft.Win32 .SystemEvents SessionSwitchEv entHandler for
        details.

        ....
        SystemEvents.Se ssionSwitch += new
        SessionSwitchEv entHandler (SystemEvents_S essionSwitch);
        ....
        // unhook static eventhandler when application terminates!!!
        ....
        //Handle event
        static void SystemEvents_Se ssionSwitch(obj ect sender,
        SessionSwitchEv entArgs e)
        {
        Console.WriteLi ne("The session is switched. Reason={0}", e.Reason);
        }

        Willy.


        Comment

        • BC3Tech

          #5
          Re: Handle the Windows Lock Desktop event/message?

          Awesome solution Willy! I had no idea that .net 2.0 had this
          built-in... definitely a bit easier than working with APIs. I
          implemented this solution in about 4.6 seconds ;)

          Thanks again!

          Comment

          Working...