If I kill explorer.exe like this:

private static void KillExplorer()
    var processes = Process.GetProcessesByName("explorer");
    Console.Write("Killing Explorer... ");
    foreach (var process in processes)

It restarts immediately.

But if I use taskkill /F /IM explorer.exe, or kill it from the task manager, it doesn't restart.

Why is that? What's the difference? How can I close explorer.exe from code without restarting it? Sure, I could call taskkill from my code, but I was hoping for a cleaner solution...

  • 1
    What Windows version are you using? – t3hn00b Nov 27 '12 at 11:25
  • 3
  • Are you trying to write a kiosk app? – Jodrell Nov 27 '12 at 12:22
  • @t3hn00b, I tried it on XP and 7, with the same results. – Thomas Levesque Nov 27 '12 at 13:47
  • @DanBarzilay, the accepted answer to this question doesn't work, and the others are not very helpful either. Please don't close. – Thomas Levesque Nov 27 '12 at 13:49

I can't say that I haven't cheated to get the answer. All credits go to morguth for his post here.

What he has suggested (and proved work on my Win7 and XPMode) is that there is a registry key that forces the shell to restart automatically. By using the following code you disable that.

RegistryKey ourKey = Registry.LocalMachine;
ourKey = ourKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
ourKey.SetValue("AutoRestartShell", 0);
// Kill the explorer by the way you've post and do your other work
ourKey.SetValue("AutoRestartShell", 1)
  • Thanks for you answer. I've seen this post before, but it doesn't seem like a very good idea to change a system-wide setting just for a one-shot action. What if a crash occurs after you set the value to 0 and before you set it back to 1? – Thomas Levesque Nov 27 '12 at 17:40
  • @ThomasLevesque well my home Win has that option disabled (set to 0) that's why I've asked you about the Windows version (I thought it was version specific). So I think nothing problematic will happen yet you can test it yourself - googling around didn't show any strange behaviour. NVidia driver installer kills the explorer when installing new drivers, so if they do it (and they probably do it roughly the same way) I doubt anything really dangerous might happen. Yet it's up to you and your requirements. – t3hn00b Nov 28 '12 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.