Python Forum

Full Version: Odd behavior when starting Explorer.exe
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to successfully restart Explorer.exe (Windows 10) via Python 3.x. I'm using the subprocess module and it's run() function. Here's what I've observed:

* I always terminate explorer.exe via "taskkill /im explorer.exe /f". So throughout this post, that is how I do it.

* Restarting the process is trivial. I kill explorer, followed by calling "<path>\explorer.exe". Terminating explorer is fine and dandy, but restarting it through this method halts the calling script after the line to launch it.

* Terminating explorer.exe, followed by restarting it via calling "start explorer.exe" does not halt the script, but the behavior is not right. Doing it this way just launches a window/folder, the desktop is not restored. The script proceeds, however.

* Now on the Windows command line, terminating explorer and launching it via "start" works fine. The desktop is restored.

So, does anyone have experience restarting explorer, or any ideas how to make the run() call behave exactly as if I killed explorer via the command prompt? I need to restart explorer and have the script continue to process. There's something different about calling a command via run(), but I wonder if it can be fixed with an argument or combination of arguments.
Further digging has led me to the following update as to point 3:

The reason starting explorer via "start explorer.exe" caused the desktop (taskbar, background, icons) to not be displayed is because I am using a 32 bit Python on 64 bit Windows. Something happens with starting the 32 bit explorer, not 64 bit. It can be corrected by the following sending the following argument to run(): 'c:\\windows\\sysnative\\cmd.exe /k start explorer.exe'. That starts the complete desktop by bypassing a native a Windows behavior.

However, the script still halts after the run() call. Something with launching a 64bit explorer via 32 bit Python? I don't know, but I'll keep digging.
Well, I can launch Explorer in a separate thread and the main thread will continue uninterrupted. That'll do, but I'd still like to know why launching Explorer halts the script.