View previous topic :: View next topic |
Author |
Message |
Aslan Valued Contributor
Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Sat Mar 12, 2005 1:29 am Post subject: Handling Windows Messages |
|
|
I have an app that runs as a service using srvany from MS.
I works great except that when the user logs off the apps stops running.
I have traced the problem to this which I found on MS TechNet:
Quote: | After a user exits a Win32 graphical application, all top-level windows receive the WM_QUERYENDSESSION and WM_ENDSESSION messages. Some Win32 applications stop running when they receive these messages. To keep a Win32 application running after a user exits, all Win32 applications must use the default Windows procedure when they receive these messages.
After a user exits a Win32 character-based application, the application receives a CTRL_LOGOFF_EVENT event from the console. To continue running a Win32 character-based application after a user exits, if the application registers a console event handler using SetConsoleCtrlHandler, it must ignore the CTRL_LOGOFF_EVENT event. |
Basically I need VDS to ignore only these messages.
I believe that "OPTION MSGEVENT" would work but I haven't found an adequit example of how to use the feature.
Any help with this would be greatly appreciated.
Thanks in advance,
Aslan |
|
Back to top |
|
|
Aslan Valued Contributor
Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Sat Mar 12, 2005 1:51 am Post subject: |
|
|
Would this be correct?
I used Codescript's API constraints for the message numbers.
Code: |
OPTION MSGEVENT,$11,WM_QUERYENDSESSION,HANDLED
OPTION MSGEVENT,$16,WM_ENDSESSION,HANDLED
:WM_QUERYENDSESSION
%A = User Session Ended
goto evloop
:WM_ENDSESSION
%A = User Session Ended
goto evloop
|
|
|
Back to top |
|
|
ShinobiSoft Professional Member
Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Sat Mar 12, 2005 2:50 am Post subject: |
|
|
Looks good to me _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
Back to top |
|
|
PGWARE Web Host
Joined: 29 Dec 2001 Posts: 1562
|
Posted: Sat Mar 12, 2005 5:26 am Post subject: |
|
|
If I am not mistaken on the WM_QUERYENDSESSION message you need to specifically send back a notification denying the shutdown/endsession process. |
|
Back to top |
|
|
Aslan Valued Contributor
Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Sat Mar 12, 2005 1:56 pm Post subject: |
|
|
You're not mistaken |
|
Back to top |
|
|
jules Professional Member
Joined: 14 Sep 2001 Posts: 1043 Location: Cumbria, UK
|
Posted: Sun Mar 13, 2005 5:16 pm Post subject: |
|
|
I noticed this with my services. The reason seemed to be that the service was receiving a WM_CLOSE notification, which was generating a CLOSE event that my script was dutifully obeying.
I was using XYNTService, so I didn't notice this for a while because it checks that the service is running every minute (I think that is user selectable) and restarts it if it isn't. But the solution is to make your CLOSE label the same as LOOP. _________________ The Tech Pro
www.tech-pro.net |
|
Back to top |
|
|
Aslan Valued Contributor
Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Sun Mar 13, 2005 10:03 pm Post subject: |
|
|
Jules,
How did this affect system shutdown or the ability for the service to stop the app purposefully? |
|
Back to top |
|
|
jules Professional Member
Joined: 14 Sep 2001 Posts: 1043 Location: Cumbria, UK
|
Posted: Mon Mar 14, 2005 11:08 am Post subject: |
|
|
I didn't find any problems with this. However, it would appear that on shutdown the service is simply terminated. So there is no way to close the service cleanly. If you have any files open, such as a log, you should open, write and close them each time, and not keep them open.
There is no way that I know of for a VDS 5 app running as a service to receive notification to shut down, unless you made a customised version of XYNTService that wrote something to the registry, which the VDS app could test for. VDS 5 was never designed with a view to being able to create services.
VDS 6 will support the creation of services that use either the VDS 5 or 6 runtime, but services that use the VDS 5 runtime will still have this limitation. The VDS 6 runtime will have the ability to receive an event on service shutdown, so it will be possible to create services that close down cleanly. _________________ The Tech Pro
www.tech-pro.net |
|
Back to top |
|
|
henrywood Contributor
Joined: 21 Sep 2004 Posts: 66 Location: Copenhagen, Denmark
|
Posted: Mon Aug 29, 2005 12:44 am Post subject: Handling windows messages in Services |
|
|
Hi guys !
It would appear that simply doing
OPTION MSGEVENT,$11,WM_QUERYENDSESSION,
OPTION MSGEVENT,$16,WM_ENDSESSION,
would leave your service running after user log off and would properly call the CLOSE label upon shutdown if using my ServiceCTL modified version of XYNTService with a VDS based service
I am NOT sure that the two lines above are actually needed when using ServiceCTL (see http://www.vdsworld.com/search.php?view_mode=fileinfo&file_id=474 for info)
Can anyone confirm this ? |
|
Back to top |
|
|
|