Change the restart logic. Replace each instance of subprocess.Popen('explorer.exe') with a start call through cmd.exe. For example:
Kill existing explorer
subprocess.run(['taskkill', '/F', '/IM', 'explorer.exe'], check=True)
Use cmd’s ‘start’ to relaunch the Explorer shell
subprocess.run(['cmd', '/c', 'start', '', 'explorer.exe'], check=True)
Change the restart logic. Replace each instance of subprocess.Popen('explorer.exe') with a start call through cmd.exe. For example:
Kill existing explorer
subprocess.run(['taskkill', '/F', '/IM', 'explorer.exe'], check=True)
Use cmd’s ‘start’ to relaunch the Explorer shell
subprocess.run(['cmd', '/c', 'start', '', 'explorer.exe'], check=True)