Solved

vb.NET: Detect whether program is closed because of reboot or just program crash.

Posted on 2003-11-24
8
343 Views
Last Modified: 2010-05-18
I'm creating a vb.NET program that monitors two processes that are running in task manager. java.exe and inetinfo.exe.  Basically, my program tells me if either of those processes are shut down (crash) and pages me.

My question is this: Is there a way to tell if the program that I'm monitoring (java.exe or inetinfo.exe) are shut down because someone is rebooting the box vs. the programs being stopped by an administrator or crashing.

Each time these programs stop I get notification via pager and I DON'T want to get paged if the server is being rebooted for maintenance or whatever.

Thanks 1,000,000
gtosi
0
Comment
Question by:gtosi
8 Comments
 
LVL 42

Expert Comment

by:frodoman
ID: 9812142
I'd suggest a timer or counter of some sort.  

When your app finds the monitored program is not running, it could increment a counter or start a timer.  Then tie to code to page you into the time elapsed / count, etc. - basically provide enough of a delay for a reboot to occur and the program to begin running again.

Of course for this to work you'll need to make sure whenever your app finds the monitored program is running, it'll need to zero out the counter / timer.
0
 

Author Comment

by:gtosi
ID: 9812280
I guess, in short what I need is something like this:

For lack of a better term I need the "onServerBeingShutdown(Rebooted)" event.

I want paged when my process inetinfo.exe drops out of taskmgr but not when it's because server is rebooted.
0
 
LVL 42

Expert Comment

by:frodoman
ID: 9812316
I was hoping to offer an alternate possibility (which may or may not work for you).

I'm not aware of any event such as what you're looking for.  I would be surprised if it existed because if it exists then I would think it would be possible for malicious code to intercept the event - that could lead to a virus that won't let you turn off your computer (at least short of yanking the plug out of the wall...).
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 9813896
Hi,

Is your program running on the same server as the two processes being monitored? If so, you could just delay sending the page long enough that the OS gets around to shutting down your program as well if a shutdown is happening. So say after the program notices that one of the processes is stopped, it could set a flag. If, after say 15 seconds, the program is still running, then send out the page. You might need to tweak the delay a little, and its not the most elegant of solutions, but it should work.

Zaphod.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 250 total points
ID: 10590219
Moderator, my recommended disposition is:

    Accept Z_Beeblebrox's comment(s) as an answer.
   **** note: Another option is handle WM_ENDSESSION

Dan Rollins -- EE database cleanup volunteer
0
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 10590250
I think the comment made by DanRollins (WM_ENDSESSION) is actually the best solution to this problem, I just wasn't aware of it when I first commented on this question. But the WM_ENDSESSION windows message is in effect an "onServerBeingShutdown(Rebooted)" event!

Zaphod.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

776 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