Prevent explorer from automatically restarting

For certain actions it is required that the Windows Explorer is stopped in order to avoid open file handles or other actions that can be done while the Explorer is running. Windows is configured to restart the Explorer automatically when its process is terminated. I wrote a small PowerShell script that checks the current setting, disables it if necessary, kills the process and then restarts it and optionally restores the setting if it was set in the first place. You can find it here:

This script has to be executed with administrator privileges as it changes values in the system wide part of the registry.