471,594 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

Intercept crash of an external exe

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!

Nov 23 '06 #1
3 3973
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/pro....mspx?mfr=true

I think that will work for you.

-Chris

"lookaround" <lo********@virgilio.itwrote in message
news:11*********************@j44g2000cwa.googlegro ups.com...
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!
Nov 24 '06 #2
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..
2) Or, you could just tell windows not to put that dialog up anymore. Check
out
http://www.microsoft.com/technet/pro....mspx?mfr=true

I think that will work for you.

-Chris

"lookaround" <lo********@virgilio.itwrote in message
news:11*********************@j44g2000cwa.googlegro ups.com...
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!
Nov 24 '06 #3
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

"lookaround" <lo********@virgilio.itwrote in message
news:11**********************@45g2000cws.googlegro ups.com...
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..
>2) Or, you could just tell windows not to put that dialog up anymore.
Check
out
http://www.microsoft.com/technet/pro....mspx?mfr=true

I think that will work for you.

-Chris

"lookaround" <lo********@virgilio.itwrote in message
news:11*********************@j44g2000cwa.googlegr oups.com...
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!
Nov 25 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by JK Peck | last post: by
9 posts views Thread by fishbaugher | last post: by
5 posts views Thread by Purple-D | last post: by
12 posts views Thread by benjamin.krulewitch | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.