简体   繁体   English

c#如何禁止cmd.exe进程中的“不支持的16位应用程序”窗口弹出

[英]c# how to suppress “Unsupported 16-Bit Application” window popup in cmd.exe process

Short explanation: 简短说明:

Starting a cmd.exe process from C# with an improper exe or com file as parameter opens an " Unsupported 16-Bit Application " window. 使用不正确的exe或com文件作为参数从C#启动cmd.exe进程将打开“ 不支持的16位应用程序 ”窗口。 Any idea how to detect / suppress this window and report an error to the caller? 知道如何检测/隐藏此窗口并将错误报告给调用者吗?

Longer explanation: 更长的解释:

In porting our server application from VMS to .NET I wrote a VMS/DCL command interpreter as we need to support DCL command scripts and we are not allowed to touch the business layer which supports DCL scripts. 在将服务器应用程序从VMS移植到.NET时,我写了一个VMS / DCL命令解释器,因为我们需要支持DCL命令脚本,并且不允许我们接触支持DCL脚本的业务层。 The DCL interpreter now also needs to call native programs and cmd.exe scipts. DCL解释器现在还需要调用本机程序和cmd.exe脚本。

For this, my DCL interpreter supports a "DCL" command which starts a cmd.exe process in a hidden window, redirects the input/output and/or passes a DCL parameter as script to cmd.exe . 为此,我的DCL解释器支持“ DCL”命令,该命令在隐藏窗口中启动cmd.exe进程,重定向输入/输出和/或将DCL参数作为脚本传递给cmd.exe Now, when a bad script file get's passed (ex. a DCL command file with a ".COM" extension), cmd.exe tries to start the file/program and launches a modal " Unsupported 16-Bit Application " window and this regardless of WindowStyle and CreateNoWindow. 现在,当传递了错误的脚本文件(例如,带有“ .COM”扩展名的DCL命令文件)时, cmd.exe尝试启动文件/程序并启动模式“ 不支持的16位应用程序 ”窗口,无论WindowStyle和CreateNoWindow的集合。

As this runs on the server, I need to close/suppress the window and report an error back to my DCL. 当它在服务器上运行时,我需要关闭/抑制该窗口并将错误报告给我的DCL。

My solution: 我的解决方案:

The only solution I could find till now was to check the MainWindowTitle of the launched process for " Unsupported 16-Bit Application ", kill the process and report an error back to DCL. 到目前为止,我唯一能找到的解决方案是检查启动的进程的MainWindowTitle中的“ 不支持的16位应用程序 ”,终止该进程并将错误报告给DCL。

But unfortunately as this runs in a separat process and DCL not necessarely needs to wait for the process to end, it's not defined at which point the title shows up and the check may be too early and fail. 但是不幸的是,由于这是在分离过程中运行的,并且DCL不必等待过程结束,因此未定义标题出现的时间,并且检查可能为时过早而失败。

Any ideas? 有任何想法吗?

SetErrorMode is infact the solution and it's even a documented errorMode. SetErrorMode实际上是解决方案,甚至是记录在案的errorMode。

The following line of code disables the message box: 下面的代码行禁用消息框:

var oldMode = SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS);

The following line will set it back to the original value: 下一行将其设置回原始值:

SetErrorMode(oldMode );

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

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