Starting explorer.exe isn't working properly in C#
Asked Answered
S

1

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.

Shulman answered 25/11, 2010 at 16:52 Comment(1)
Also, this question is fairly similar - #1118517Snowinsummer
S
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.

Snowinsummer answered 25/11, 2010 at 17:0 Comment(5)
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!Shulman
Do not hardcode the path to explorer. Call Envoromment.WindowsDirectory.Santo
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.Shulman
@Burak: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolders.SystemRoot), "explorer.exe")Rarefied
Good to hear and glad I could help out,Snowinsummer

© 2022 - 2024 — McMap. All rights reserved.