When you select the explorer process in taskmgr, the button will be "restart" instead of "end task/end process". After clicking restart, explorer shows in "windows process" in taskmgr again as before, but "kill&start" will not. Then I have some questions:
My current code for kill&start explorer (C#)
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName.ToUpper().Contains("EXPLORER"))
{
p.Kill();
p.WaitForExit();
}
}
Process.Start("explorer.exe");
And I tried to use cmd
taskkill /f /im explorer.exe
explorer
I debugged taskmgr
, and found out that while explorer
does get special treatment (taskmgr!WdcApplicationsMonitor::_HandleRestartExplorer
) it's just simply calling TerminateProcess
.
Then, it checks the registry for AutoRestartShell (I'm on Windows 11, and it's set by default; can't say for older Windows);
if set then taskmgr
is done; the OS will restart explorer
.
If not set, then it calls WdcRunTaskAsInteractiveUser(L"%windir%\\explorer.exe", nullptr, 9)
(undocumented api in wdc.dll
, and also the meaning of 9
unknown; seems like a bit flag, and requires further digging) to restart explorer
.
Note: Somehow with taskkill /f /im explorer.exe
, explorer
doesn't restart even when AutoRestartShell
is set.