forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Handling Windows Messages

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced Help for VDS 5 & Up
View previous topic :: View next topic  
Author Message
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Sat Mar 12, 2005 1:29 am    Post subject: Handling Windows Messages Reply with quote

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
View user's profile Send private message Send e-mail
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Sat Mar 12, 2005 1:51 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
ShinobiSoft
Professional Member
Professional Member


Joined: 06 Nov 2002
Posts: 790
Location: Knoxville, Tn

PostPosted: Sat Mar 12, 2005 2:50 am    Post subject: Reply with quote

Looks good to me Wink
_________________
Bill Weckel
ShinobiSoft Software

"The way is known to all, but not all know it."
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
PGWARE
Web Host


Joined: 29 Dec 2001
Posts: 1562

PostPosted: Sat Mar 12, 2005 5:26 am    Post subject: Reply with quote

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
View user's profile Send private message
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Sat Mar 12, 2005 1:56 pm    Post subject: Reply with quote

You're not mistaken Wink
Back to top
View user's profile Send private message Send e-mail
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Sun Mar 13, 2005 5:16 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Sun Mar 13, 2005 10:03 pm    Post subject: Reply with quote

Jules,

How did this affect system shutdown or the ability for the service to stop the app purposefully?
Back to top
View user's profile Send private message Send e-mail
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Mon Mar 14, 2005 11:08 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
henrywood
Contributor
Contributor


Joined: 21 Sep 2004
Posts: 66
Location: Copenhagen, Denmark

PostPosted: Mon Aug 29, 2005 12:44 am    Post subject: Handling windows messages in Services Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced Help for VDS 5 & Up All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group