最近要解决一个问题,就是explorer.exe。用了好多网友的建议,代码去实现一次性关闭explorer.exe,并且不会自动恢复的功能。
首先explorer.exe是管理window电脑任务栏和window桌面显示的功能。说白了就是不想看到开机后所有相关window界面。
我试了很多个方法,都是explorer.exe会自动恢复,查了相关资料,发现用代码实现window会自己进行轮询并恢复explorer.exe,但是我看到用任务管理器去关闭的时候就不会自动恢复。
所有就想着用cmd命令试试,果然运行
"taskkill /f /im explorer.exe"就不会出现自己恢复的情况。
Process process = new Process();
string strOutput = string.Empty;
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
process.StandardInput.WriteLine("taskkill /f /im explorer.exe"+ "&exit");
process.StandardInput.AutoFlush = true;
即可以一劳永逸的关闭 explorer.exe。
当然kill之后需要恢复explorer.exe,当你的explorer.exe已经存在了,而你再次恢复explorer.exe就会直接弹出库文件夹。不符合需求,所以要判断一下explorer.exe是否存在,如果存在就不要继续去恢复explorer.exe,如果不存在就去恢复explorer.exe。
if (Process.GetProcessesByName("explorer").Length <= 0)
{
System.Diagnostics.Process.Start("C:\\Windows\\explorer.exe");
}
mark 一下 ,不经常做这部分的内容,担心以后忘记。