Suppress "Program cannot start due to missing X.dll" error pop-up

I have a Python program that uses os.system to execute various commands. (It cannot use subprocess because it must be backward compatible before Python 2.0.)

On Windows, sometimes the command references DLLs in an unusual directory, and therefore I get the infamous "The program does not start because X.dll is missing" error pop-up.

Windows error popup with title "cl.exe - System Error" and text "The program can't start because mspdb80.dll is missing from your computer. Try reinstalling the program to fix this problem."

My question is not about how to get the team to find all its dll files. I already know how to do this. I want to know how can I tell Windows not to show this dialog when a dll is missing? Instead, the child process should print an error message in stderr (which was redirected to the file in the os.system call) and fail (by calling os.system to return the error code). That way, my program could fix the error and report it in its own way, instead of hanging until someone comes to click OK.

MSDN is usually my friend, but this time I get nothing but advice on how to deal with specific missing DLLs, which is nice and all, but not what I need this time.

Again, this is a situation with extreme backward compatibility: I need a solution that works with Python 2.7 or any old version, up to 2.0. He should also work on all popular versions of Windows (XP, Vista, 7, 8). Working with older Windows is highly desirable, but 100% is not required. In addition, third-party modules and auxiliary programs written in any other language are not an option. (I believe the .BAT file will be fine if this is the only way to do this.)

+6
source share
1 answer

The dialog box can be disabled for the calling process with SetErrorMode . However, you should read the LoadLibrary documentation to find that the “missing DLL at boot time” qualifies as one of the “critical errors” on SEM_FAILCRITICALERRORS .

The error mode inherits child processes if they are not created using CREATE_DEFAULT_ERROR_MODE , and it seems that CMD.EXE does not set this flag when creating subprocesses. Therefore setting the error mode on startup in my Python script really prohibits the dialog box in a situation that I care about ...

 if sys.platform == 'win32': try: import ctypes # SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX|SEM_NOOPENFILEERRORBOX ctypes.windll.kernel32.SetErrorMode(0x0001|0x0002|0x8000) except: pass 

This is not an optimal solution: the subprocess terminates with a specific error code (0xC0000135 - is not actually documented as a "missing DLL", but, obviously, from what appears when searching by this number), but the details - for example, the DLL is missing - are reset to floor. I still hope to find somewhere somewhere that causes the bootloader to report stderr details.

+8
source

Source: https://habr.com/ru/post/943651/


All Articles