我写了这个小函数,按名称搜索进程并将其杀死:请参阅下面的代码
Process[] procList = Process.GetProcesses();
RegistryKey expKey = Registry.LocalMachine;
expKey = expKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
expKey.SetValue("AutoRestartShell", 0);
using (StreamWriter writer = new StreamWriter(@"C:\test\progtemp\Procs1.Txt", true))
{
int i = 0;
foreach (Process procs in procList)
{
writer.WriteLine(string.Format("Process Name {0} -- Process ID {1} -- Session ID {2}", procs.ProcessName, procs.Id, procs.SessionId));
if (procs.ProcessName == "explorer")
{
procList[i].Kill();
}
i++;
}
}
expKey.SetValue("AutoRestartShell", 1);
Run Code Online (Sandbox Code Playgroud)
我很好奇为什么当我告诉它杀死资源管理器时它会自动重启.我怎样才能使它不重新启动而你必须进入任务管理器并手动重新启动它?
如果您运行regedit并进入HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon,您可以找到名为AutoRestartShell的密钥.
设置为0将禁止explorer.exe重新启动.虽然我个人说最好不要乱用Registry,但如果你真的需要,请使用Registry.SetValue将代码中的值更改为0(文档:https://msdn.microsoft.com /en-us/library/5a5t63w8(v=vs.110).aspx)
编辑:灵感取自https://technet.microsoft.com/en-us/library/cc939703.aspx
编辑2:挖掘一下谷歌得出以下结果,这解释了一切稍微好一点:https://superuser.com/questions/511914/why-does-explorer-restart-automatically-when-i-kill-it-与过程杀
| 归档时间: |
|
| 查看次数: |
663 次 |
| 最近记录: |