Windows - Popen with wShowWindow in startupinfo, not affecting display

I am trying to do something simple, for example, get calc.exe, in order to minimize, but this does not happen.

import subprocess import win32gui import win32con info = subprocess.STARTUPINFO() info.dwFlags |= subprocess.STARTF_USESHOWWINDOW info.wShowWindow = win32con.SW_SHOWMINIMIZED x = subprocess.Popen("calc.exe", startupinfo = info) 

It appears as always, no matter what I provide for wShowWindow .

+4
source share
1 answer

I think you already understood this, but for the benefit of other readers here I take:

The problem is with calc.exe , not Python and your code. To prove this, try running "notepad.exe" (or "wordpad.exe") and it will work - also note that you may need to specify the full path to the target .exe depending on where it is located.

In particular, what’s wrong corresponds to the STARTUPINFO structure, a member of wShowWindow :

For GUI processes, the first time ShowWindow is called, its nCmdShow parameter is ignored. wShowWindow indicates the default value. In subsequent ShowWindow calls, the wShowWindow member is used if the nCmdShow parameter of the ShowWindow parameter is set to SW_SHOWDEFAULT.

So, this means that when you first start the program and call ShowWindow() it completely ignores everything that you passed to wShowWindow in the STARTUPINFO structure. Then, when calling ShowWindow() again, it will only use your provided value for wShowWindow if the program calls ShowWindow() with the nCmdShow parameter set to SW_SHOWDEFAULT .

Thus, it seems that it is impossible to hide the GUI window if the program itself provides its value for nCmdShow in ShowWindow() , so it just seems that the trial version and the error see which programs do this, for example, .exe notepad allows you to hide it. and calc.exe you cannot.

+1
source

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


All Articles