3

I'm trying to make a simple application in C# that allows me to kill and enable explorer.exe. I need such program so that I can play Age of Empires 2 properly, because it does not like explorer.exe for some reason (I believe it has to do with Aero). So I made two buttons, one that enables explorer.exe and the other one disables it. Killing explorer.exe went ok, but enabling didn't.

I read on a few sites that you have to use the Process.Start(); to start a process. So I made Process.Start("explorer.exe");. After killing explorer.exe, it executed the previous line but instead of having my taskbar back, it opened 'Libraries' only without giving my taskbar back. I also tried Process.Start("explorer.exe", "-p"); (I saw it somewhere), but that opened 'My Documents'.

What can I do so it starts the process explorer.exe so that I have the things like the taskbar back? I can still launch it properly with Command Prompt/Task Manager/Run.

Braiam
  • 1
  • 11
  • 47
  • 78
Burak
  • 667
  • 1
  • 11
  • 19
  • Also, this question is fairly similar - http://stackoverflow.com/questions/1118017/how-do-i-start-explorer-using-process-class-in-c – Dave Nov 25 '10 at 16:57

1 Answers1

0

Solution in that topic:

foreach(Process p in Process.GetProcesses())
{
    try
    {
        // Compare it with "explorer".
        if(p.MainModule.ModuleName.Contains("explorer") == true)
        {
            p.Kill();
        }
    }
    catch(Exception e)
    {
        // Do some exception handling here.
    }

    // Restart explorer.
    Process.Start("explorer.exe");
}

Give that a shot.

Braiam
  • 1
  • 11
  • 47
  • 78
Dave
  • 6,905
  • 2
  • 32
  • 35
  • 1
    Well, actually the link you gave previously (the one you said was similar to my question) did the trick. I did Process.Start(@"c:\\windows\\explorer.exe"); which worked perfectly. Thanks! – Burak Nov 25 '10 at 17:07
  • 2
    Do not hardcode the path to explorer. Call Envoromment.WindowsDirectory. – Joshua Nov 25 '10 at 17:17
  • It doesn't really matter though, it's just for my self. Though I'm very new to c#, how would the exact code look like if I do it with Environment.WindowsDirectory? Also visual c# doesn't recognize the 'WindowsDirectory' part. – Burak Nov 25 '10 at 17:28
  • 1
    @Burak: `Path.Combine(Environment.GetFolderPath(Environment.SpecialFolders.SystemRoot), "explorer.exe")` – SLaks Nov 25 '10 at 17:41
  • Good to hear and glad I could help out, – Dave Nov 26 '10 at 08:38