Problem with Killing windows explorer?

前端 未结 5 583
梦毁少年i
梦毁少年i 2020-12-17 02:34

I need to kill windows explorer\'s process (explorer.exe), for that

lets say i use a native NT method TerminateProcess

It works but the problem is that the

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 03:01

    I have some researches and these are reslts:

    Windows will restart explorer after it closed -except by Task Manager-.

    So you should change the related 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);
    

    For changing a registry key the program should run as administrator:

    • You can show UAC prompt to user to run application as administrator as explaining in this Answer. And if UAC is turned off I direct you to this Answer.
    • You can embed a manifest file in the exe, which will cause Windows Seven to always run the program as an administrator, As explaining in this Answer.
    • You should know you can't force your process starts as administrator; so you can run your process inside your process as another process! You can use this blog post or this answer.
    • You can also use reg command with this [Microsoft Windows Documentation].6.

    After setting that -restarting explorer- off: This code can close explorer :

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

提交回复
热议问题