i am trying to write a program that close explorer then runs another program.
i am getting a problem when trying to close explorer using the following code:
foreach (Process p in Process.GetProcesses())
if (p.MainModule.ModuleName.Contains("explorer"))
p.Kill();
can somebody please let me know why it is doing this and provide a solution
CHEERS
p.s. this is not a malicous program, it is going to run a game that doesn't work properly when explorer is in the background
The problem is that you can have multiple versions of Explorer running at any one point in time... and you usually need at least one of them. The shell that hosts the Start Menu is actually an instance of Explorer. So if you close all instances of Explorer, you'll also be shutting down the main shell, which is not what you want to do.
However, the fastest way to do get all instances of Explorer and kill them is:
foreach (Process p in Process.GetProcessesByName("explorer"))
{
p.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