I wrote this little function that searches for a process by name and kills it: see code below
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);
I'm curious why when I tell it to kill explorer it automatically restarts. How can I make it so that it does not restart and you have to go into task manager and manually restart it?