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. MFC silent executable running from system account not recieveing WM_QUERYENDSESSION message ?? [modified]

MFC silent executable running from system account not recieveing WM_QUERYENDSESSION message ?? [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
22 Posts 6 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.
  • T ThatsAlok

    It will sound funny, where actually are you catching WM_QUERYENDSESSION Message?

    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
    Never mind - my own stupidity is the source of every "problem" - Mixture

    cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

    K Offline
    K Offline
    Kushagra Tiwari
    wrote on last edited by
    #6

    Hey Alok, I am trapping the message in WndProc(Windows Procedure Method) of the application. Then using the message handler for WM_QUERYENDSESSION I am returning false to abort logoff/shutdown and doing my functionality in between. Regards, Kushagra

    1 Reply Last reply
    0
    • H Hans Dietrich

      The MSDN article has a link at the bottom to an example. It's not MFC, but you should be able to use it in an MFC app.

      Best wishes, Hans


      [Hans Dietrich Software]

      K Offline
      K Offline
      Kushagra Tiwari
      wrote on last edited by
      #7

      Thanks Hans, But yes we can only intercept the message here and not abort shutdown here :( Kushagra

      1 Reply Last reply
      0
      • K Kushagra Tiwari

        Hello all, I have made an MFC application with invisible window and invisible in Applications tab of taskmanager designed to run in different sessions depending upon the number of users who are logged into the system. Thus, according to user events the instances used to capture logoff/Shutdown/Logon events for that particular session.Also, I have made one instance of this executable to run in 'SYSTEM' account to capture scheduled shutdown in cases when no user was logged on the machine. However in this case 'WM_QUERYENDSESSION' is never recieved by this running instance of my application which runs in 'SYSTEM' account.Can some one tell me how to abort scheduled shutdown in Windows from an application running in system account , in a case when no user is logged on in the machine. Regards, Kushagra I hate coding but I luv to develop :)

        modified on Wednesday, October 21, 2009 9:22 AM

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #8

        Kushagra Tiwari wrote:

        However in this case 'WM_QUERYSESSION' is never recieved by this running instance...

        Where is this message being sent from? Is that process sending it to your window directly, or to all top-level windows via HWND_BROADCAST?

        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        K 1 Reply Last reply
        0
        • D David Crow

          Kushagra Tiwari wrote:

          However in this case 'WM_QUERYSESSION' is never recieved by this running instance...

          Where is this message being sent from? Is that process sending it to your window directly, or to all top-level windows via HWND_BROADCAST?

          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          K Offline
          K Offline
          Kushagra Tiwari
          wrote on last edited by
          #9

          Hello David, Generally when windows receives shutdown event it broadcasts WM_QUERYENDSESSION to all top level windows applications , here the issue is as my MFC application is running silently from 'System' account somehow the broadcasted message from Windows is not able to identify this as a Top level windows application.Hence, this application never recives the message whcih is why I am stuck here. All i need to do is to stop scheduled shutdown from a process running in 'System' account. I am open to suggestions , if this can be done in any other way too. Regards, Kushagra

          D 1 Reply Last reply
          0
          • K Kushagra Tiwari

            Hello David, Generally when windows receives shutdown event it broadcasts WM_QUERYENDSESSION to all top level windows applications , here the issue is as my MFC application is running silently from 'System' account somehow the broadcasted message from Windows is not able to identify this as a Top level windows application.Hence, this application never recives the message whcih is why I am stuck here. All i need to do is to stop scheduled shutdown from a process running in 'System' account. I am open to suggestions , if this can be done in any other way too. Regards, Kushagra

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #10

            Kushagra Tiwari wrote:

            Generally when windows receives shutdown event it broadcasts WM_QUERYENDSESSION to all top level windows applications...

            I'm very familar with all of this. I was inquiring about the WM_QUERYSESSION message.

            "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            R K 2 Replies Last reply
            0
            • D David Crow

              Kushagra Tiwari wrote:

              Generally when windows receives shutdown event it broadcasts WM_QUERYENDSESSION to all top level windows applications...

              I'm very familar with all of this. I was inquiring about the WM_QUERYSESSION message.

              "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              R Offline
              R Offline
              Roger Stoltz
              wrote on last edited by
              #11

              DavidCrow wrote:

              I was inquiring about the WM_QUERYSESSION message

              Most likely a typo since the heading of the post says WM_QUERYENDSESSION, don't you think? :-\

              "It's supposed to be hard, otherwise anybody could do it!" - selfquote
              "High speed never compensates for wrong direction!" - unknown

              D 1 Reply Last reply
              0
              • D David Crow

                Kushagra Tiwari wrote:

                Generally when windows receives shutdown event it broadcasts WM_QUERYENDSESSION to all top level windows applications...

                I'm very familar with all of this. I was inquiring about the WM_QUERYSESSION message.

                "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                K Offline
                K Offline
                Kushagra Tiwari
                wrote on last edited by
                #12

                Hey David, I am sorry It was a TYPO from my side :confused: . But kindly suggest some way so that I can achieve my goal. Kushagra

                D 1 Reply Last reply
                0
                • R Roger Stoltz

                  DavidCrow wrote:

                  I was inquiring about the WM_QUERYSESSION message

                  Most likely a typo since the heading of the post says WM_QUERYENDSESSION, don't you think? :-\

                  "It's supposed to be hard, otherwise anybody could do it!" - selfquote
                  "High speed never compensates for wrong direction!" - unknown

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #13

                  One can choose to make assumptions, or not. I've been around long enough to know that folks don't always ask the right question.

                  "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  R 1 Reply Last reply
                  0
                  • K Kushagra Tiwari

                    Hey David, I am sorry It was a TYPO from my side :confused: . But kindly suggest some way so that I can achieve my goal. Kushagra

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #14

                    Kushagra Tiwari wrote:

                    But kindly suggest some way so that I can achieve my goal.

                    Do you receive the message if the window is visible? What about if it's running in a non-SYSTEM account?

                    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    K 1 Reply Last reply
                    0
                    • D David Crow

                      Kushagra Tiwari wrote:

                      But kindly suggest some way so that I can achieve my goal.

                      Do you receive the message if the window is visible? What about if it's running in a non-SYSTEM account?

                      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      K Offline
                      K Offline
                      Kushagra Tiwari
                      wrote on last edited by
                      #15

                      I have made it invisible , and I recieve this message for all accounts other than SYSTEM account and they are working pretty neat , but only for this particular case for monitering scheduled shutdowns through system account my logic goes for a toss as the message WM_QUERYENDSESSION never comes to the application. Kushagra

                      D 1 Reply Last reply
                      0
                      • D David Crow

                        One can choose to make assumptions, or not. I've been around long enough to know that folks don't always ask the right question.

                        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        R Offline
                        R Offline
                        Roger Stoltz
                        wrote on last edited by
                        #16

                        DavidCrow wrote:

                        I've been around long enough to know that folks don't always ask the right question.

                        I'm well aware of that and you are not the only one. For the record my post wasn't meant as criticism as you seem to have understood it.

                        "It's supposed to be hard, otherwise anybody could do it!" - selfquote
                        "High speed never compensates for wrong direction!" - unknown

                        1 Reply Last reply
                        0
                        • K Kushagra Tiwari

                          I have made it invisible , and I recieve this message for all accounts other than SYSTEM account and they are working pretty neat , but only for this particular case for monitering scheduled shutdowns through system account my logic goes for a toss as the message WM_QUERYENDSESSION never comes to the application. Kushagra

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #17

                          With services, there is the "Allow service to interact with desktop" option. Is there a similar option for an app running as the SYSTEM account?

                          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          K 1 Reply Last reply
                          0
                          • D David Crow

                            With services, there is the "Allow service to interact with desktop" option. Is there a similar option for an app running as the SYSTEM account?

                            "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                            K Offline
                            K Offline
                            Kushagra Tiwari
                            wrote on last edited by
                            #18

                            I am afraid , I did not found any thing of such kind with an application running from System account. Kushagra

                            K 1 Reply Last reply
                            0
                            • K Kushagra Tiwari

                              I am afraid , I did not found any thing of such kind with an application running from System account. Kushagra

                              K Offline
                              K Offline
                              Kushagra Tiwari
                              wrote on last edited by
                              #19

                              Does anybody knows the solution ??? Kushagra

                              D C 2 Replies Last reply
                              0
                              • K Kushagra Tiwari

                                Does anybody knows the solution ??? Kushagra

                                D Offline
                                D Offline
                                David Crow
                                wrote on last edited by
                                #20

                                You might want to also pose this question to the folks in the microsoft.public.vc.language newsgroup. Several sharp folks are active there.

                                "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                1 Reply Last reply
                                0
                                • K Kushagra Tiwari

                                  Does anybody knows the solution ??? Kushagra

                                  C Offline
                                  C Offline
                                  Covean
                                  wrote on last edited by
                                  #21

                                  From MSDN: "Console applications receive shutdown notifications in their handler routines. To register a console handler, use the SetConsoleCtrlHandler function. Service applications receive shutdown notifications in their handler routines. To register a service control handler, use the RegisterServiceCtrlHandlerEx function." Maybe that helps.

                                  1 Reply Last reply
                                  0
                                  • K Kushagra Tiwari

                                    Hello all, I have made an MFC application with invisible window and invisible in Applications tab of taskmanager designed to run in different sessions depending upon the number of users who are logged into the system. Thus, according to user events the instances used to capture logoff/Shutdown/Logon events for that particular session.Also, I have made one instance of this executable to run in 'SYSTEM' account to capture scheduled shutdown in cases when no user was logged on the machine. However in this case 'WM_QUERYENDSESSION' is never recieved by this running instance of my application which runs in 'SYSTEM' account.Can some one tell me how to abort scheduled shutdown in Windows from an application running in system account , in a case when no user is logged on in the machine. Regards, Kushagra I hate coding but I luv to develop :)

                                    modified on Wednesday, October 21, 2009 9:22 AM

                                    R Offline
                                    R Offline
                                    Roger Stoltz
                                    wrote on last edited by
                                    #22

                                    Kushagra Tiwari wrote:

                                    I have made an MFC application with invisible window and invisible in Applications tab of taskmanager .... I have made one instance of this executable to run in 'SYSTEM' account

                                    Does this mean that you have created a service?

                                    Kushagra Tiwari wrote:

                                    how to abort scheduled shutdown in Windows from an application running in system account

                                    Are you certain that you really want to do this even if it's possible? What do you mean by 'scheduled'? Personally I find it suspicious that you have created an application that runs "invisible" from user perspective that aims to block the system from being brought down. I would consider it to be a very anti-social application that I wouldn't want running on any of my machines. However, if an application calls ::ExitWindowsEx() with the EWK_FORCE parameter, WM_QUERYENDSESSION will not be sent - all processes will be terminated and possibly with data lost. How do you distinguish from a 'scheduled' shutdown and one triggered by a user in your message handler or callback? I guess the user won't be able to bring the system down either.... What if your application runs on a machine with UPS; the power is lost and the UPS service wants to bring the system down safely? Will you block it if possible? I guess my question really is "what are to trying to accomplish and why"? There may be a better solution.

                                    "It's supposed to be hard, otherwise anybody could do it!" - selfquote
                                    "High speed never compensates for wrong direction!" - unknown

                                    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