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?
If you run regedit and go into HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon, you can find there a key named AutoRestartShell.
Settings that to 0 would disallow explorer.exe from rebooting. Although I personally say it's not the best idea to mess with Registry just for that but if you really need to, make use of Registry.SetValue to change that value to 0 from the code (documentation: https://msdn.microsoft.com/en-us/library/5a5t63w8(v=vs.110).aspx)
Edit: inspiration taken from https://technet.microsoft.com/en-us/library/cc939703.aspx
Edit 2: digging a bit into google came up with the following result which explains everything slightly better: https://superuser.com/questions/511914/why-does-explorer-restart-automatically-when-i-kill-it-with-process-kill
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With