|
Prev: Register a DLL
Next: Reverse-engineering USB protocol
From: Jos Scherders on 1 Jul 2008 16:00 Hi all, I know applications can handle WM_QUERYENDSESSION when the user logs off but I have two questions. Is WM_QUERYENDSESSION sent to ALL processes runnning on the Winsta0/desktop are just the one initiated from the logon session of the console user ? Is there any other way to "undo" the logoff ? E.g. we want to do considerable amount of processing before we want the logoff sequence to complete/continue ? When the user logs off he may be prompted to save any unsaved data by some application. One option he has is to cancel which will effectively stop the logoff sequence. I assume this is done by processes WM_QUERYENDSESSION. Is there a similar option to stop the user initiated shutdown sequence or does a shutdown sequence wait for the user to logoff (e.g. I can also use WM_QUERYENDSESSION) in this case ? Are there standard hooks I can use to do some work in a shutdown sequence (or even make it impossible for the to do a shutdown) ? Last question, what is the "standard" solution in XP to handle problems related to services shutting down in random order ? (In our case it is specific to SQL Server, we run into problems because SQL server is shutdown while we really wanted to save some more data :)) Lot of question but I really hope someone can help me here. Thanks a lot, Jos
From: Kellie Fitton on 1 Jul 2008 17:46 On Jul 1, 1:00 pm, "Jos Scherders" <thro...(a)home.nl> wrote: > Hi all, > > I know applications can handle WM_QUERYENDSESSION when the user logs off but > I have two questions. Is WM_QUERYENDSESSION sent to ALL processes runnning > on the Winsta0/desktop are just the one initiated from the logon session of > the console user ? > > Is there any other way to "undo" the logoff ? E.g. we want to do > considerable amount of processing before we want the logoff sequence to > complete/continue ? > > When the user logs off he may be prompted to save any unsaved data by some > application. One option he has is to cancel which will effectively stop the > logoff sequence. I assume this is done by processes WM_QUERYENDSESSION. Is > there a similar option to stop the user initiated shutdown sequence or does > a shutdown sequence wait for the user to logoff (e.g. I can also use > WM_QUERYENDSESSION) in this case ? Are there standard hooks I can use to do > some work in a shutdown sequence (or even make it impossible for the to do a > shutdown) ? > > Last question, what is the "standard" solution in XP to handle problems > related to services shutting down in random order ? (In our case it is > specific to SQL Server, we run into problems because SQL server is shutdown > while we really wanted to save some more data :)) > > Lot of question but I really hope someone can help me here. > Thanks a lot, > > Jos Hi, Try to create a hook into the windows message WM_QUERYENDSESSION so you can have a bit more head start, otherwise the system could assumes an unresponsive process is dead, and takes actions against it. Remember every application gets the message WM_QUERYENDSESSION, and in your reply you can say "yes" or "no" but your answer is only one vote, the first application to respond to this message stops the polling by windows. Also, use the API SetProcessShutdownParameters() to set the shutdown parameters for the current calling process. You need to use a system-wide hook, for example, WH_CALLWNDPROC to monitor messages being sent, and WH_CALLWNDPROCRET to monitor the messages handlers returning, and a hook procedure in a .DLL file. You can use the following APIs to handle a hook: SetWindowsHookEx() CallNextHookEx() UnhookWindowsHookEx() http://msdn.microsoft.com/en-us/library/ms686227(VS.85).aspx http://msdn.microsoft.com/en-us/library/aa376890.aspx http://msdn.microsoft.com/en-us/library/ms644990(VS.85).aspx http://msdn.microsoft.com/en-us/library/ms644974(VS.85).aspx http://msdn.microsoft.com/en-us/library/ms644993(VS.85).aspx http://msdn.microsoft.com/en-us/library/ms644959.aspx Kellie.
From: Alexander Grigoriev on 1 Jul 2008 22:12 What we see is only the console session gets QUERY, all other sessions are only getting WM_ENDSESSION. This is because there is no way to get user confirmation for disconnected sessions. You can stay for quite long in your WM_ENDSESSION handler. If you want your service shut down before SQL, I think that your should declare it dependent on that. Handle all final tasks in SERVICE_CONTROL_SHUTDOWN handler. "Jos Scherders" <thrower(a)home.nl> wrote in message news:uZKdkU72IHA.4928(a)TK2MSFTNGP04.phx.gbl... > Hi all, > > I know applications can handle WM_QUERYENDSESSION when the user logs off > but I have two questions. Is WM_QUERYENDSESSION sent to ALL processes > runnning on the Winsta0/desktop are just the one initiated from the logon > session of the console user ? > > Is there any other way to "undo" the logoff ? E.g. we want to do > considerable amount of processing before we want the logoff sequence to > complete/continue ? > > When the user logs off he may be prompted to save any unsaved data by some > application. One option he has is to cancel which will effectively stop > the logoff sequence. I assume this is done by processes > WM_QUERYENDSESSION. Is there a similar option to stop the user initiated > shutdown sequence or does a shutdown sequence wait for the user to logoff > (e.g. I can also use WM_QUERYENDSESSION) in this case ? Are there standard > hooks I can use to do some work in a shutdown sequence (or even make it > impossible for the to do a shutdown) ? > > Last question, what is the "standard" solution in XP to handle problems > related to services shutting down in random order ? (In our case it is > specific to SQL Server, we run into problems because SQL server is > shutdown while we really wanted to save some more data :)) > > Lot of question but I really hope someone can help me here. > Thanks a lot, > > Jos >
From: Stefan Kuhr on 2 Jul 2008 02:51 Hi Alexander, Alexander Grigoriev wrote: > <snip> > If you want your service shut down before SQL, I think that your should > declare it dependent on that. Handle all final tasks in > SERVICE_CONTROL_SHUTDOWN handler. > No, the service dependency is only of relevance during startup of the system, where it establishes a service startup order. It does not establish a shutdown order. In order to have more time for a service to shutdown, you have to assign to the WaitToKillServiceTimeout value in HKLM\System\CurrentControlSet\Control a value that is long enough and then duefully and repeatedly call SetServiceStatus with SERVICE_STOP_PENDING and a dwWaitHint value that is the value you specified in WaitToKillServiceTimeout, after having received a SERVICE_CONTROL_SHUTDOWN or a SERVICE_CONTROL_PRESHUTDOWN notification and while doing the shutdown processing tasks in your service. -- Stefan
From: Volodymyr M. Shcherbyna on 2 Jul 2008 05:44 Well, playing with SQL server just before OS goes into shutdown is unreliable. -- Volodymyr, blog: http://www.shcherbyna.com/ (This posting is provided "AS IS" with no warranties, and confers no rights) "Stefan Kuhr" <kustt110(a)gmx.li> wrote in message news:%230OfkCB3IHA.2336(a)TK2MSFTNGP03.phx.gbl... > Hi Alexander, > > Alexander Grigoriev wrote: >> <snip> >> If you want your service shut down before SQL, I think that your should >> declare it dependent on that. Handle all final tasks in >> SERVICE_CONTROL_SHUTDOWN handler. >> > > No, the service dependency is only of relevance during startup of the > system, where it establishes a service startup order. It does not > establish a shutdown order. In order to have more time for a service to > shutdown, you have to assign to the WaitToKillServiceTimeout value in > HKLM\System\CurrentControlSet\Control a value that is long enough and then > duefully and repeatedly call SetServiceStatus with SERVICE_STOP_PENDING > and a dwWaitHint value that is the value you specified in > WaitToKillServiceTimeout, after having received a SERVICE_CONTROL_SHUTDOWN > or a SERVICE_CONTROL_PRESHUTDOWN notification and while doing the shutdown > processing tasks in your service. > > > -- > Stefan
|
Pages: 1 Prev: Register a DLL Next: Reverse-engineering USB protocol |