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