Restart Explorer Process using c#

First of all, you have to kill all running processes of explorer.exe(usually only one) and then start it with full path specified, otherwise a new explorer window will open.

void _restart_explorer()
{
    try
    {
	foreach (Process p in Process.GetProcesses())
	{
		try
		{
			Process[] exp = Process.GetProcessesByName("explorer");
			foreach (Process explorer in exp)
				explorer.Kill();
		}
		catch { }
	}
 
	Process.Start(Path.Combine(Environment.GetEnvironmentVariable("windir"), "explorer.exe"));
    }
    catch {  }
}
Categories: C# Tags: , ,
%d bloggers like this: