0

I have the following code:

from subprocess import call
import time

call('taskkill /IM explorer.exe /F', shell=True)

time.sleep(2)

call(["start", "explorer.exe"],shell=True)

When i run it, explorer.exe (Taskbar, environment etc.) closes, but on call function, it starts the Windows Explorer - File explorer.

If i close the explorer.exe (Let's say, from task manager) and then on cmd start explorer.exe it works as intended. Presumably, the code above does the same, but the results are not.

What is going on under the hood?

Cybrus
  • 74
  • 13
  • works fine on windows 10. Taskbar disappears, then reappears... – Jean-François Fabre Dec 24 '16 at 09:55
  • @Jean-FrançoisFabre Weird, i am running windows 10 as well. – Cybrus Dec 24 '16 at 10:16
  • can you replace the last line by `call("explorer.exe")` ? your script won't end, but maybe you'll see a difference. – Jean-François Fabre Dec 24 '16 at 12:27
  • Is Python running elevated? If Explorer is started elevated, it registers a task named "\CreateExplorerShellUnelevatedTask" that reloads Explorer without elevation. Maybe something is wrong there. Kill Explorer and try running it from an elevated command prompt. – Eryk Sun Dec 24 '16 at 18:03
  • @Jean-FrançoisFabre, no difference sighted. – Cybrus Dec 24 '16 at 18:22
  • @eryksun what do you mean by "elevated"? Administrator Rights? – Cybrus Dec 24 '16 at 18:22
  • I must admit It is puzzling. – Jean-François Fabre Dec 24 '16 at 18:25
  • Yes, with administrator rights, but elevated also means the process [mandatory integrity control](https://msdn.microsoft.com/en-us/library/bb648648) level is elevated to high. Non-elevated defaults to medium integrity level. When you "run as administrator", the shell uses the appinfo service to launch a program elevated. – Eryk Sun Dec 24 '16 at 18:29

1 Answers1

0

Was having trouble with this.

Turns out it's related to opening explorer.exe from a 32-bit process. Running your module from a 64-bit instance of Python should give the desired behavior.

This post led me to this conclusion: Restarting explorer.exe only opens an explorer window

magpie
  • 1
  • 1