Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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)
    {
        process.Kill();
        process.WaitForExit();
    }
    Console.WriteLine("Done");
}

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 stackoverflow.com Nov 28 '12 at 16:00

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

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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