Problem with Killing windows explorer?

I need to kill the Windows Explorer process (explorer.exe), for this

lets say that I use my own NT TerminateProcess method

This works, but the problem is that the conductor starts up again, maybe windows do it, anyway. When I kill explorer.exe using the Windows task manager, it does not return, it remains killed.

I want to do everything that taskmanager does through my application.

Edit:
Thanks to @sblom, I decided that a quick registry trick did the trick. Although its smart to hack, apparently the task has a cleaner way to do this, but I decided to go with @sblom for now.

+5
source share
5 answers

The "real" solution. (Full program. Tested to work with Windows 7.)

using System;
using System.Runtime.InteropServices;

namespace ExplorerZap
{
    class Program
    {
        [DllImport("user32.dll")]
        public static extern int FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll")]
        public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);

        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool PostMessage(int hWnd, uint Msg, int wParam, int lParam);

        static void Main(string[] args)
        {
            int hwnd;
            hwnd = FindWindow("Progman", null);
            PostMessage(hwnd, /*WM_QUIT*/ 0x12, 0, 0);
            return;
        }
    }
}
+8
source

From Technet :

You can set the registry HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoRestartShellkey to 0 and it will no longer automatically restart.

+14
source

- api , ( Win 7 Professional):

    public static class Extensions
    {
        public static void ForceKill(this Process process)
        {
            using (Process killer = new Process())
            {
                killer.StartInfo.FileName = "taskkill";
                killer.StartInfo.Arguments = string.Format("/f /PID {0}", process.Id);
                killer.StartInfo.CreateNoWindow = true;
                killer.StartInfo.UseShellExecute = false;
                killer.Start();
                killer.WaitForExit();
                if (killer.ExitCode != 0)
                {
                    throw new Win32Exception(killer.ExitCode);
                }
            }
        }
    }

, Win32Exception , Kill - , Windows Explorer.

, Process:

    foreach (Process process in Process.GetProcessesByName("explorer"))
    {
        process.ForceKill();
    }

, taskkill (, - : http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskkill.mspx?mfr=true).

+4

, TerminateProcess WM_QUIT . , , :

http://www.replicator.org/node/100

Windows explorer.exe TerminateProcess, .

+2

, reslts:

Windows explorer - -.

, RegistryKey:

RegistryKey regKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default).OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\Winlogon", RegistryKeyPermissionCheck.ReadWriteSubTree);
if (regKey.GetValue("AutoRestartShell").ToString() == "1")
    regKey.SetValue("AutoRestartShell", 0, RegistryValueKind.DWord);

:

  • UAC , . UAC , .
  • exe, Windows Seven . .
  • You should know that you cannot force your process to run as an administrator; so you can run your process inside your process as another process! You can use this blog post or this one.
  • You can also use the command regwith this [Microsoft Windows Documentation]. 6 .

After setting this parameter -restarting explorer-off: this code may close explorer:

Process[] ps = Process.GetProcessesByName("explorer");
foreach (Process p in ps)
    p.Kill();
0
source

All Articles