Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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...

share|improve this question

migrated from Nov 28 '12 at 16:00

This question came from our site for professional and enthusiast programmers.

What Windows version are you using? – t3hn00b Nov 27 '12 at 11:25
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
up vote 3 down vote accepted

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)
share|improve this answer
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .