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

試著忘記壹切 提交于 2019-12-19 09:59:16

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4279293/starting-explorer-exe-isnt-working-properly-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!