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 


How to tell vds when pc wants to shut down ?

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
Dave England
Newbie


Joined: 22 Aug 2003
Posts: 3

PostPosted: Fri Aug 22, 2003 3:06 pm    Post subject: How to tell vds when pc wants to shut down ? Reply with quote

He ya ! Wink

I want to log the time I spent working with my pc
so everytime computer shuts down I want to
write the variable in text file.

ok not a problem so far, but:
How I know when Computer logs off, reboot or shutdown?

I had the following idea:

:close
info application closed
....blaŽbla write variable
exit


hmmm dont works but Ive seen it in several applications, for example my
image editing software asks when im trying to shut down... "you want to save your work"

thx in advance if you could help me ! Smile
Back to top
View user's profile Send private message
PGWARE
Web Host


Joined: 29 Dec 2001
Posts: 1566

PostPosted: Fri Aug 22, 2003 4:46 pm    Post subject: Reply with quote

Windows sends all windows a WM_QUERYENDSESSION message, this tells each and every program opened in Windows that it is about to terminate (shutdown, restart).

It may be possible to intercept such a message with VDS and appropriately write your files to disk.

Windows will then immediately send a WM_ENDSESSION, you must then pass back True or False to tell it you are ready to allow a shutdown. Sending a false will halt windows from shutting down and/or may cause your application to terminate and a forced shutdown/restart will occur. You should in almost all circumstances send back a TRUE message to allow you application to close and let Windows terminate.
Back to top
View user's profile Send private message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1060
Location: India

PostPosted: Fri Aug 22, 2003 5:35 pm    Post subject: Reply with quote

This is possible in VDS 5.x using built in fn
using
OPTION MSGEVENT, $11, shutevent
and then under

:shutevent
IF @NOT(@ZERO(@MSGPARAMS( W ) ))
Event name do whatever you want
EXIT
END
GOTO EVLOOP

SORRY IT MAY NOT BE AS SIMPLE (above code cannot work). You should process the message and give a return value. If you set it to false(0) then windows will stop shutdown and after you complete your work you should your self call system shutdown.

However if you are writing someting small to text file that can be completed under 1sec. then above idea may help.

Regards

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension


Last edited by CodeScript on Fri Aug 22, 2003 6:14 pm; edited 3 times in total
Back to top
View user's profile Send private message Visit poster's website
jules
Professional Member
Professional Member


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

PostPosted: Fri Aug 22, 2003 6:00 pm    Post subject: Reply with quote

Quote:
I had the following idea:

:close
info application closed
....blaŽbla write variable
exit


This should work in VDS 5. My system tray apps all use it to shut down cleanly. Earlier versions didn't branch to the close label on shutdown, though...

_________________
The Tech Pro
www.tech-pro.net
Back to top
View user's profile Send private message Visit poster's website
Dave England
Newbie


Joined: 22 Aug 2003
Posts: 3

PostPosted: Fri Aug 22, 2003 6:21 pm    Post subject: nice, thx Reply with quote

thanx for all answers Cool Very Happy
you guys helped me alot Very Happy
Back to top
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Fri Aug 22, 2003 11:53 pm    Post subject: Reply with quote

I've been wondering how to do this too for awhile now. So is it
better to use the OPTION MSGEVENT or just the close label with
VDS 5? Smile

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1060
Location: India

PostPosted: Sat Aug 23, 2003 2:54 am    Post subject: Reply with quote

FreezingFire wrote:
I've been wondering how to do this too for awhile now. So is it
better to use the OPTION MSGEVENT or just the close label with
VDS 5? Smile

Sorry FF I don't know I may test some time. FF did you test the XYNTService.exe I gave you long back ?
Just wanted to know - No obligations. Smile

Hi Dave England
Just a few Ideas.
If the write operation under close label still does not work then
continuosly write to file under a timer say every 0.1 second the current
time.
Accuracy will be upto 0.2 seconds. I think it should be OK for general
purposes.

Code:

:EVLOOP
WAIT EVENT,0.1

:TIMER
REM Add Your file write commands here
GOTO EVLOOP


If you are on NT based system (Win 2k/NT/XP) and VDS 5 and willing to use windows API then you have even more options.

1.Run the app as a NT service (use XYNTService.exe a freeware utility) so that it doesnot exit even if the user logs off untill the computer is
shutdown!.

2. Use GetUserName API to get the currently logged on user* every time you write to file under the timer and write it with the time. (make seperate ini sections for each user)

This way you can get the session duration info for each of the users.

* = You may have to call another exe to get this info as the service will be run under "system account". Not very sure.

I don't know if you want these advanced options but if you want any more
info let me know. I will help whatever I can.


Regards

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Sun Aug 24, 2003 12:21 am    Post subject: Reply with quote

hi pg,

i tried before to use your suggestion and got nowhere...would you be able to put together some sample code on using WM_ENDSESSION to detect within a vds program when windows shutsdown ...

thanks in advance

serge

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
PGWARE
Web Host


Joined: 29 Dec 2001
Posts: 1566

PostPosted: Sun Aug 24, 2003 6:01 pm    Post subject: Reply with quote

Hi Serge,
Unfortunately I haven't played around with the LOADLIB examples enough to write up an example yet. I think CodeScript gave you the correct function to use in VDS directly which most likely is using these api's anyway:

OPTION MSGEVENT, $11, shutevent
Back to top
View user's profile Send private message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1060
Location: India

PostPosted: Sun Aug 24, 2003 6:20 pm    Post subject: Reply with quote

I will try if it works sometime but will take lot of time on my slow computer rebooting every test.
BTW if it works as jules said then that would be better as with PGWARE's and my example shut down is not delayed anyway to offer addditional benefit. If you want that I think it's too complicated.As I said
Quote:
You should process the message and give a return value. If you set it to false(0) then windows will stop shutdown and after you complete your work you should your self call system shutdown.


Regards

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Sun Aug 24, 2003 6:34 pm    Post subject: Reply with quote

How about using this? Smile

Code:
option shutdown,<label>

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1060
Location: India

PostPosted: Mon Aug 25, 2003 3:03 am    Post subject: Reply with quote

skit I think this should be the correct solution. It will then execute the code and on completion the DefWindowProc function in the VDS runtime will return true so that system can shutdown. Everything has already been coded into VDS !!
Embarassed I assumed that there is no such function even without searching the help (RTFM ... You know what it is Smile )

thoroughly.

Regards

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Mon Aug 25, 2003 8:50 am    Post subject: Reply with quote

thanks for your answer pg...i was after a solution for vds 4.x as the one suggested is for vds 5...anyone have any idea how to use WM_ENDSESSION in vds 4.x to pick up within a vds program if windows is going to shutdown?

thanks in advance

serge

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1060
Location: India

PostPosted: Mon Aug 25, 2003 10:15 am    Post subject: Reply with quote

IMHO no solution short of writing a custom dll.
_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help 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