End process challenge

Posted on 2003-03-07
Medium Priority
Last Modified: 2010-04-01
Dear experts,

I have a task to write a program that will be started
from the registry (Run) and ended with the Shut Down. The
problem is that I need to end the execution of the program gracefully, as it will do a lot of calculations, it needs
to save its data before the Shut Down.

It'd be also great if there was a way to save all data when user tries to terminate the process from the Task

The program should be able to run on most Windows platforms.

I appreciate your help.
Question by:qwertypal
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
  • 3
  • 2
LVL 86

Expert Comment

ID: 8088422
If it is a GUI app: Process 'WM_ENDSESSION' and 'WM_QUERYENDSESSION'

Author Comment

ID: 8092068
Actually, my app is an API executable that runs without any windows. On Terminate Process from Task Manager
it doesnt seem to receive any messages, nor at Shut Down.
Is there still a way to capture those messages?

I would've implemented this app as a Service, but my goal was to make it run on most Windows platforms.


Expert Comment

ID: 8095633
First of all, I would abstract my startup and shutdown, and actually make it a service on nt/2k/xp.  Secondly, on win9x, I think what you can do is create a window which is not visible.  That should allow you to catch the messages that you will need.  There's more info here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/system_shutdown.asp

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 8097586
Thanks, Brian, that helped.

What about when a user tries to end the process from the Task Manager? I suppose no messages get posted in this case, right?


Accepted Solution

bkrahmer earned 300 total points
ID: 8098122
From what I can tell, end process from the task manager is a brutal kill.  If it is, then the only thing you can do is checkpoint your data at time intervals.  That's what's nice about using a service on nt platforms.  You can't kill services from the task manager, so you won't have to worry about that case.


Author Comment

ID: 8099926
You are right, Brian

Thank you.

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

762 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