shutting down an vb exe  when OS shuts down

Posted on 2002-07-14
Last Modified: 2010-05-02

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..............

Question by:navneetha
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7153582
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...


Accepted Solution

AlonHirsch earned 50 total points
ID: 7153694

When you use the Sleep API - your app stops responding for the entire duration it is sleeping - it does not use any CPU cycles.
To circumvent this - you need to sleep for shorter periods (maybe 10 seconds at a time) and then use a Doevents.
This will ensure that your program does checks for activity etc. every 10 seconds and then becomes dormant again.


Expert Comment

ID: 7153872
you could use wait for WaitForMultipleObjects....
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 7153908
Hi Sabnis,

What objects would you wait for ?


Expert Comment

ID: 7154441
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

Expert Comment

ID: 7154454
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

Expert Comment

ID: 7154831
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
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'.

LVL 49

Expert Comment

ID: 8012179
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

Expert Comment

ID: 8095576
Comment from expert accepted as answer

E-E Admin

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question