0

I have a program that, on error, will stop running. When it stops running, the "start" button is enabled and the "stop" button disables. While the program is running (after clicking "start"), the "start" button disables.

My goal is to write a program that, on interval (2 minutes), checks the status of the "start" button and sends an SMTP email when the "start" button becomes enabled. Thus letting me know when the program has stopped running.

I've been able to use FindWindow to find the program but I haven't been able to locate the button, let alone have my program differentiate enabled vs. disabled.

Using Spy++, the Handle of the button is 000A0B0A. The Style of the button when it is enabled is 54000000; disabled it is 5C000000. The program, or form/window, Handle is 00050B2C.

My question is: What command, if any, can I use to check the Style of that particular button (Handle 00A0B0A)?

SeaSharp
  • 1
  • 2
  • Is the code for the program where these buttons are present under your control? –  Nov 29 '10 at 21:09
  • If you have the chance to modify the program, listen to SpeksETC advice. – VVS Nov 29 '10 at 21:26
  • No, the program isn't mine and the author is unwilling to modify it. Also, the ability to send an email isn't there. – SeaSharp Nov 29 '10 at 23:04

1 Answers1

4

It sounds like what you are generally need is to add observability to your program so you can monitor its state (running, stopped, error, etc.).

I would suggest a different (and possibly simpler approach) that doesn't rely on the UI which could change in the future and which may be more extendable in the case that you would like to observe different information on your application in the future.

Why don't you instead fire status events from your program on error? There are several different ways to do this from the product (wcf, remoting, writing to the event viewer, etc.) and have your external application register for these events and act accordingly (e.g. send an email)?

It may be a little extra work in the beginning (though I'm not sure since you are already running into issues with your approach, and writing a simple wcf service that fires events doesn't take that much time) but I think well worth it in the future.

SpeksETC
  • 1,003
  • 2
  • 7
  • 13
  • I agree completely with your response. However, it's not my program. The author of the program is unwilling to modify it, hence the route I've begun. – SeaSharp Nov 29 '10 at 23:02