Intercept crash of an external exe

L

lookaround

Hi everyone,
I need some help...
I call an external exe (a command-line tool) with Process.Start through
this code:

try
{
p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = ExePath;
p.StartInfo.Arguments = "";
p.Start();
p.PriorityClass = ProcessPriorityClass.BelowNormal;
}
catch (Exception exc) //Win32Exception err
{
Console.Writeline(exc.Message);
}


p.WaitForExit();
if (p.ExitCode == 0)
{
tbLog.Text += "All ok." + Environment.NewLine;
}
else
{
tbLog.Text += "Exit code: " + p.ExitCode.ToString() +
Environment.NewLine;
}




If the external exe crashes, it displays a window:
"An error occurred ... application will be closed"
"For further information ... click here" (I translate from Italian).
and the two buttons "Debug" and "Close"

Until I click on Debug or Close the calling application freezes.
After I click on one of the two buttons, the calling app return
responsive and logs the err message (exit code).

The fact that application freezes while executing external exe is not a
problem; the problem is that the app has to be run in un-attended
mode...
So it should intercept the external crash, handle the crash and go on,
not wait for a click by the user.

I should also check if the external exe runs for more than a fixed
number of seconds: if it runs longer, I should have to kill the exe and
handle the unfinished execution (without no external input or click)

Any help?

Thank you very much in advance for any idea!
 
C

Chris

If I understand you correctly:
1) You are launching an exe using Process.Start()
2) When the exe you launched crashes, windows puts up a dialog asking if you
want to debug it
3) Until something clicks the dialog, the exe doesn't return, and your
origanal app is waiting
4) You want to know how to clear that dialog automatically

If all that is correct, then this might help:
1) You could spawn a seperate thread and enumerate windows - then send a
click event to the correct button whenever you see the dialog you want
cleared
2) Or, you could just tell windows not to put that dialog up anymore. Check
out
http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/regentry/11499.mspx?mfr=true

I think that will work for you.

-Chris
 
L

lookaround

Thank you for tips!
If I understand you correctly:
1) You are launching an exe using Process.Start()
2) When the exe you launched crashes, windows puts up a dialog asking if you
want to debug it
3) Until something clicks the dialog, the exe doesn't return, and your
origanal app is waiting
4) You want to know how to clear that dialog automatically

You understood perfectly.

If all that is correct, then this might help:
1) You could spawn a seperate thread and enumerate windows - then send a
click event to the correct button whenever you see the dialog you want
cleared

I'm executing the exe from an asp.net application page.
I'm not so experienced with Thread and capture external windows events
and clicks...
Should you suggest me some tutorial or web page where I can found some
code to start from?
Thanks again in advance..
 
C

Chris

I wasn't actually recommending option 1 as a viable choice :}

I recommend you make option 2 work for you if you can; if for some reason
you can't, reply back to me (not the whole group) and I'll help you get your
problem solved.

-Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top