0

My goal requires a programmatic solution for terminating dotnet.exe when it has a second-chance exception (e.g. using Stop-Process or taskkill for termination). Can this be done?

The batch file I was provided has a command like:

dotnet exec Some.Namespace.Project.dll -t

The only alternative I have in mind would be to kill the dotnet.exe process before the second-chance exception. Timing this correctly requires a way to determine when an output file is no longer being modified and/or when a specific string appears in the standard output that indicates processing for the output file is finished.

Please note, I am attempting to automate the solution in a shell language (PowerShell, Bash, or CMD commands), but I will accept solutions in other languages too (e.g. C#, Python, etc.). I have been scripting outside of the batch file I was provided, but I can also edit the batch file itself.

ligei
  • 1
  • 3
  • Please note, the user is given a WER dialog option to debug because a debugger is installed - even though it wasn't in use. As such, it contradicts the outcome mentioned in the answer to this [linked question](https://stackoverflow.com/questions/47343331/how-to-programmatically-detect-an-application-has-crashed-in-windows/47358395). – ligei Dec 17 '19 at 05:33
  • Clarification: I want to terminate a process that is started by a batch file, but not until the process has served its purpose. The process is guaranteed to have finished serving its purpose when it has a second-chance exception. The action of killing the process should be automated (i.e. I need to detect the second-chance exception in order to trigger the command to terminate). – ligei Jan 03 '20 at 01:19

1 Answers1

0

A viable way of detecting the second-chance exception is via the Windows Error Reporting service (WerSvc), which has a process name of WerFault.exe. This is the dialog window that displays with the options for Debug and Close program. This probably appears because I have Visual Studio installed, and might have different text without a debugger available.

It isn't a good solution to just detect the presence of the process, but it is getting the job done for what I need it to do.

ligei
  • 1
  • 3