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. Intercepting a Logoff

Intercepting a Logoff

Scheduled Pinned Locked Moved C#
tutorialquestion
5 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.
  • O Offline
    O Offline
    ormonds
    wrote on last edited by
    #1

    I am writing a tiny app which will be triggered in GPO by a user logoff. The app simply checks that the user has done some required housework. Can anyone show me how to interrupt the logoff (and remain logged on) depending on the answer?

    OriginalGriffO 1 Reply Last reply
    0
    • O ormonds

      I am writing a tiny app which will be triggered in GPO by a user logoff. The app simply checks that the user has done some required housework. Can anyone show me how to interrupt the logoff (and remain logged on) depending on the answer?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Best you can do is handle the SystemEvents.SessionEnding Event (Microsoft.Win32) | Microsoft Docs[^] - it catches both shutdown and logoff. It's cancelable, so your app can request that the system remains up - but it's only a request, it mayu not be honoured depending on what the system is doing. As the documentation says

      Quote:

      It provides no guarantee that the session will not end.

      And it won't detect and cancel a user pulling the plug out of the wall ... :laugh:

      Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      O 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Best you can do is handle the SystemEvents.SessionEnding Event (Microsoft.Win32) | Microsoft Docs[^] - it catches both shutdown and logoff. It's cancelable, so your app can request that the system remains up - but it's only a request, it mayu not be honoured depending on what the system is doing. As the documentation says

        Quote:

        It provides no guarantee that the session will not end.

        And it won't detect and cancel a user pulling the plug out of the wall ... :laugh:

        Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

        O Offline
        O Offline
        ormonds
        wrote on last edited by
        #3

        Thanks, I'll look at that. Also found this: https://bytes.com/topic/c-sharp/answers/590618-preventing-logoff-shutdown-until-c-windows-app-closed)

        D 1 Reply Last reply
        0
        • O ormonds

          Thanks, I'll look at that. Also found this: https://bytes.com/topic/c-sharp/answers/590618-preventing-logoff-shutdown-until-c-windows-app-closed)

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

          There is no way to absolutely prevent a user from logging off or shutting down the system. Even the solution you found is a "suggestion" that the system not shutdown. There is nothing you can do to prevent it as everything you come up with can be defeated just by ending the process that is your application.

          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
          Dave Kreskowiak

          O 1 Reply Last reply
          0
          • D Dave Kreskowiak

            There is no way to absolutely prevent a user from logging off or shutting down the system. Even the solution you found is a "suggestion" that the system not shutdown. There is nothing you can do to prevent it as everything you come up with can be defeated just by ending the process that is your application.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            O Offline
            O Offline
            ormonds
            wrote on last edited by
            #5

            Yes, I understand that. The intention is to remind people to do their housekeeping before logging off, perhaps even to annoy them into it.

            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