简体   繁体   English

如何从Windows的子进程中忽略阻止系统错误

[英]How to ignore blocking system errors from a child process on windows

I have a C# application running in Visual Studio 2015. It accepts arbitrary executable files and opens a command prompt through which it attempts to run them. 我在Visual Studio 2015中运行一个C#应用程序。它接受任意可执行文件,并打开一个命令提示符,尝试通过该文件运行它们。 Nothing is guaranteed about these executables though, so it is possible for them to fail to run, throwing a system error that says something like "could not locate xxx.dll". 但是,对于这些可执行文件没有任何保证,因此可能会导致它们无法运行,并引发系统错误,例如“无法找到xxx.dll”。 For a particular example, see here . 有关特定示例,请参见此处 These system errors (The header of the window sometimes says "XXXXX.exe - System Error") block the child process from ending, and since the parent process is waiting on the child, it blocks the parent too. 这些系统错误(窗口的标题有时显示“ XXXXX.exe-系统错误”)阻止子进程结束,并且由于父进程正在等待子进程,因此它也阻止了父进程。 It blocks until a human can come along and press the button, letting the child process die and the parent process continue. 它会阻塞,直到有人可以出现并按下按钮,让子进程死亡而父进程继续。 I need this to happen automatically without human intervention, preferably by just having these errors not come up in the first place. 我需要在没有人为干预的情况下自动做到这一点,最好是首先避免出现这些错误。 Looking around online, I was able to disable Windows Error Reporting through the use of regedit. 在线浏览时,我能够通过使用regedit禁用Windows错误报告。 While this does ignore errors such as "XXXXX.exe has stopped working", it does not ignore the system errors such as the one I linked. 虽然这确实忽略了诸如“ XXXXX.exe已停止工作”之类的错误,但它并未忽略诸如我链接的系统错误之类的系统错误。 How can I ignore this kind of errors? 如何忽略这种错误?

The error message you linked shows a DLL import failure where a function was loaded by id instead of its name (which often occurs when your program is a different version of the dll than expected). 您链接的错误消息显示了DLL导入失败,其中是通过id而不是其名称加载函数的(通常是在您的程序是与预期版本不同的dll版本时发生)。 I do not know of any way how to stop this message from appearing in the first place. 我不知道如何阻止此消息首先出现。

However, as the child executable is still running (showing this dialogue box), you can find this window and close it from code. 但是,由于子可执行文件仍在运行(显示此对话框),您可以找到此窗口并从代码中关闭它。

This is quite easy, as your parent process must know the child process id. 这很容易,因为您的父进程必须知道子进程的ID。 From there you can use FindWindowEx or EnumWindows to retrieve your dialogue handle (by specifying the appropriate window class name) and then use CloseWindow to close it. 从那里,您可以使用FindWindowExEnumWindows检索对话框句柄(通过指定适当的窗口类名称),然后使用CloseWindow将其关闭。

Note: you have to use P/Invoke to use these functions. 注意:您必须使用P / Invoke才能使用这些功能。

Maybe not the most elegant solution but definitely working. 也许不是最优雅的解决方案,但绝对可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM