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 / C++ / MFC
  4. Running task on shutdown

Running task on shutdown

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
7 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.
  • _ Offline
    _ Offline
    __DanC__
    wrote on last edited by
    #1

    Hi, Apologies if this has been covered somewhere but I've not found anything related. I'm working on an idea which would require a long-running task to complete at the time the user logs off, I know it's possible to delay the logoff but I was hoping to find a way to run the task as part of the logoff, something like when Windows synchronises offline folders (not sure if that's exactly the right term as I am working from memory here). Does anyone have any ideas? Thanks

    L 1 Reply Last reply
    0
    • _ __DanC__

      Hi, Apologies if this has been covered somewhere but I've not found anything related. I'm working on an idea which would require a long-running task to complete at the time the user logs off, I know it's possible to delay the logoff but I was hoping to find a way to run the task as part of the logoff, something like when Windows synchronises offline folders (not sure if that's exactly the right term as I am working from memory here). Does anyone have any ideas? Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Hi, You failed to mention what type of application you are developing. Assuming that you have a usermode application I would recommend returning FALSE to the WM_QUERYENDSESSION message[^]. However if you are developing a windows service; Here is a previous thread which covers the topic: http://www.codeproject.com/Messages/3244431/Re-Delaying-Shutdown-through-windows-service-and-e.aspx[^] Best Wishes, -David Delaune

      R _ 2 Replies Last reply
      0
      • L Lost User

        Hi, You failed to mention what type of application you are developing. Assuming that you have a usermode application I would recommend returning FALSE to the WM_QUERYENDSESSION message[^]. However if you are developing a windows service; Here is a previous thread which covers the topic: http://www.codeproject.com/Messages/3244431/Re-Delaying-Shutdown-through-windows-service-and-e.aspx[^] Best Wishes, -David Delaune

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #3

        *click* Good Answer. :)

        “Follow your bliss.” – Joseph Campbell

        1 Reply Last reply
        0
        • L Lost User

          Hi, You failed to mention what type of application you are developing. Assuming that you have a usermode application I would recommend returning FALSE to the WM_QUERYENDSESSION message[^]. However if you are developing a windows service; Here is a previous thread which covers the topic: http://www.codeproject.com/Messages/3244431/Re-Delaying-Shutdown-through-windows-service-and-e.aspx[^] Best Wishes, -David Delaune

          _ Offline
          _ Offline
          __DanC__
          wrote on last edited by
          #4

          Thanks for the reply, it is a user mode application and I know I can prevent shutdown by returning false for WM_QUERYENDSESSION but that keeps the logged in session alive, what I want to do is to run the code during the logoff, effectively after the user has been logged off. For example, when you a running Windows XP on a domain and you have offline file enabled, you will see the synchronisation window appear during the logoff to sync any remaining files back to the domain controller, I'm trying to achieve something like this. The app does not have to remain a user mode app, it could quite easily become a service if that is required but preventing the logoff is not what I'm trying to achieve. Thanks.

          L 1 Reply Last reply
          0
          • _ __DanC__

            Thanks for the reply, it is a user mode application and I know I can prevent shutdown by returning false for WM_QUERYENDSESSION but that keeps the logged in session alive, what I want to do is to run the code during the logoff, effectively after the user has been logged off. For example, when you a running Windows XP on a domain and you have offline file enabled, you will see the synchronisation window appear during the logoff to sync any remaining files back to the domain controller, I'm trying to achieve something like this. The app does not have to remain a user mode app, it could quite easily become a service if that is required but preventing the logoff is not what I'm trying to achieve. Thanks.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            __DanC__ wrote:

            Thanks for the reply, it is a user mode application

            Usermode applications are limited in their ability to delay/prevent shutdown. You are basically limited to what I described in my previous posts. I believe that you have 5 seconds to respond to the WM_QUERYENDSESSION so you might be able to perform some last-second tasks.

            __DanC__ wrote:

            For example, when you a running Windows XP on a domain and you have offline file enabled, you will see the synchronisation window appear during the logoff to sync any remaining files back to the domain controller, I'm trying to achieve something like this.

            Have you considered using Logon/Logoff[^] or Startup/Shutdown[^] scripts? This is typically what an administrator would use to execute something on shutdown/logoff. Best Wishes, -David Delaune

            _ 1 Reply Last reply
            0
            • L Lost User

              __DanC__ wrote:

              Thanks for the reply, it is a user mode application

              Usermode applications are limited in their ability to delay/prevent shutdown. You are basically limited to what I described in my previous posts. I believe that you have 5 seconds to respond to the WM_QUERYENDSESSION so you might be able to perform some last-second tasks.

              __DanC__ wrote:

              For example, when you a running Windows XP on a domain and you have offline file enabled, you will see the synchronisation window appear during the logoff to sync any remaining files back to the domain controller, I'm trying to achieve something like this.

              Have you considered using Logon/Logoff[^] or Startup/Shutdown[^] scripts? This is typically what an administrator would use to execute something on shutdown/logoff. Best Wishes, -David Delaune

              _ Offline
              _ Offline
              __DanC__
              wrote on last edited by
              #6

              Thanks for the tip, I'll have a look into the scripts and see if they can do what I need. I've just discovered SCM notifications which look promising although I haven't read enough about them to know if they can do what I want yet.

              L 1 Reply Last reply
              0
              • _ __DanC__

                Thanks for the tip, I'll have a look into the scripts and see if they can do what I need. I've just discovered SCM notifications which look promising although I haven't read enough about them to know if they can do what I want yet.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                __DanC__ wrote:

                I've just discovered SCM notifications which look promising

                Yeah, you will have some additional time I think... 20 seconds when you handle the SERVICE_CONTROL_SHUTDOWN message. You can keep posting STOP_PENDING to the SCM for some additional time. Best Wishes, -David Delaune

                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