Strange, but perhaps I am handling it the incorrect way - I need to quite simply check if explorer.exe is running, and if so kill it. However, the way I am currently achieving this, explorer.exe simply restarts after I kill it.
Normal taskkill through batch works fine though, does C# do something different?
private void Form1_Load(object sender, EventArgs e)
{
Process[] prcChecker = Process.GetProcessesByName("explorer");
if (prcChecker.Length > 0)
{
MessageBox.Show("Explorer running");
foreach (Process p in prcChecker)
{
p.Kill();
}
}
else
{
MessageBox.Show("Explorer is not running");
}
}
That's because Windows takes care of restarting explorer.exe
if it happens to die.
It is possible to delay this behavior (the setup of tortoisegit does this, for example), but it's not recommended - users are going to be pissed.
Although not C# way but you can alternatively try to set the registry key HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoRestartShell
to 0 to stop the auto restart.
EDIT:-
Try this in C#:-
RegistryKey ourKey = Registry.LocalMachine;
ourKey = ourKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
ourKey.SetValue("AutoRestartShell", 0);
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