Fredy Ferrari
Fredy Ferrari

Reputation: 41

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. 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. The DCL interpreter now also needs to call native programs and cmd.exe scipts.

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. 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.

As this runs on the server, I need to close/suppress the window and report an error back to my 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.

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.

Any ideas?

Upvotes: 3

Views: 837

Answers (1)

Fredy Ferrari
Fredy Ferrari

Reputation: 41

SetErrorMode is infact the solution and it's even a documented 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 );

Upvotes: 1

Related Questions