ShellExecuteEx with SEE_MASK_FLAG_NO_UI displays error when starting .NET app on system without .NET

StackOverflow https://stackoverflow.com/questions/2108159

  •  22-09-2019
  •  | 
  •  

문제

The ShellExecuteEx Win32 function call has a flag SEE_MASK_FLAG_NO_UI in its SHELLEXECUTEINFO structure, which should suppress any error dialogs which could be displayed because of an error when launching an application.

The MSDN documentation here is quite explicit about it:

SEE_MASK_FLAG_NO_UI
  0x00000400. Do not display an error message box if an error occurs.

In my case, I am launching a .NET executable on a Windows XP system where no .NET is installed. I systematically receive the following message, displayed by Windows in a dialog window:

Xxx.exe - Application Error
The application failed to initialize properly (0xc0000135).
Click on OK to terminate the application.
[ OK ]

I don't want the user to have to deal with this message. I'd rather get back an error code from ShellExecuteEx and be able to handle it gracefully in my program. Here is the code snippet which I am using to start the external executable:

#include <windows.h>

int wmain(int argc, wchar_t* argv[])
{
    SHELLEXECUTEINFO info;
    memset(&info, 0, sizeof(SHELLEXECUTEINFO));
    info.cbSize = sizeof(SHELLEXECUTEINFO);
    info.fMask = SEE_MASK_FLAG_NO_UI;
    info.lpVerb = L"open";
    info.lpFile = L"Xxx.exe";
    info.nShow  = SW_SHOW;
    return ShellExecuteEx (&info);
}

Is there an official way of suppressing the error message if .NET is not present on the system? Or do I have to check for this specific condition myself before executing the application (but I do not know in advance if it is a .NET app or a native app). And what if the app I am starting is missing some DLLs, for instance?

도움이 되었습니까?

해결책

The flag only tells the shell to not display an error message. It doesn't affect the UI of the process that got started. The .NET .exe really did get started so ShellExecuteEx() did it's job and saw no errors. That it decided to bomb afterwards and let the user know about it is not something you can easily fix.

다른 팁

why don't you use the CreateProcess function

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top