Link to home
Start Free TrialLog in
Avatar of navneetha
navneetha

asked on

shutting down an vb exe when OS shuts down

Hi

i have an exe running which does some task after each 15 mins. i am using the Sleep API for the appl to sleep for the specific time period. as the exe would be running for the whole day, i would like that it should automatically close when the OS is shutting down (mostly it would be Windows NT,98 or 2000). right now it gives the "appl not responding error" while shutting down.

i actually want to know if some event is generated when the appl is closed using the task manager. i have alreaday tried the Query_Unload event.

plz help..............

thanks
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

The Query_Unload should work, but maybe your code isn't complete or doesn't unload correctyl.
I assume you have a single form (invisble), maybe the form is not loaded at all to recieve the Query_unload event. You might check the load and unload events (by writing a small line to a debug file) to monitor these events...

CHeers
ASKER CERTIFIED SOLUTION
Avatar of Alon Hirsch
Alon Hirsch
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sabnis
Sabnis

you could use wait for WaitForMultipleObjects....
Hi Sabnis,

What objects would you wait for ?

Alon
wait for handle of the Thread Stop Event .... the timer elapsed event ....these are the 2 events necessary...may be other events as u need
wait for handle of the Thread Stop Event .... the timer elapsed event ....these are the 2 events necessary...may be other events as u need
navneetha, if you are sure that the form is loaded, and that you use "sleep" function with small intervals. I think the problem may be in "End" statement, use this code instead:

'In you main module
Public Const ForRelease = True
Public Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long

'Add this code instead of End statement
If ForRelease Then
  Dim ExitCode As Long
  TerminateProcess GetCurrentProcess, ExitCode
Else
   End
End If


The problem in this code is that it will terminate VB entirley if you run your program from VB, and so to avoid this problem, change the value of 'ForRelease' to 'False', and before you create your exe file, change it into 'True'.

Osama
 
Hi navneetha,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept AlonHirsch's comment(s) as an answer.

navneetha, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
Comment from expert accepted as answer

Computer101
E-E Admin