I am writing a program to kill and restart explorer but I don\'t want to hard code the location because some people install windows in different places (for example I found some
To simply kill and restart Windows Explorer you wouldn't need the path to the system folder as this is already included in the PATH environment variable (unless the user messed with it).
That short program will kill all explorer.exe instances and then restart explorer.exe:
static void Main(string[] args)
{
foreach (Process process in Process.GetProcessesByName("explorer"))
{
if (!process.HasExited)
{
process.Kill();
}
}
Process.Start("explorer.exe");
}