如何以编程方式重新启动Windows资源管理器进程 [英] How to programmatically restart windows explorer process
问题描述
我正在使用Windows Shell扩展,不幸的是,在对DLL进行更改时,我必须重新启动Windows资源管理器(因为它将DLL保留在内存中)。
I'm working on a windows shell extension, and unfortunately, when making changes to the DLL, I must restart windows explorer (since it keeps the DLL in memory).
我从Dino Esposito找到了这个程序,但是它对我不起作用。
I found this program from Dino Esposito, but it doesn't work for me.
void SHShellRestart(void)
{
HWND hwnd;
hwnd = FindWindow("Progman", NULL );
PostMessage(hwnd, WM_QUIT, 0, 0 );
ShellExecute(NULL, NULL, "explorer.exe", NULL, NULL, SW_SHOW );
return;
}
任何人都可以分享一些东西吗?
Does any one have something they can share to do this?
PS我意识到我可以去任务管理器并终止资源管理器进程,但是我只是想以一种懒惰的方式来做。
P.S. I realize that I can go to task manager and kill the explorer process, but I just want to do it the lazy way. Besides, this enables automation.
P.P.S我正在使用.NET进行开发,但是Shell重新启动功能可以是C,C ++或.NET语言。它将只是一个小的独立可执行文件。
P.P.S I am using .NET for the development, but the shell restart functionality could be in C, C++ or a .NET language. It will simply be a small stand-alone executable.
推荐答案
一个简单的解决方案:
foreach (Process p in Process.GetProcesses())
{
// In case we get Access Denied
try
{
if (p.MainModule.FileName.ToLower().EndsWith(":\\windows\\explorer.exe"))
{
p.Kill();
break;
}
}
catch
{ }
}
Process.Start("explorer.exe");
这篇关于如何以编程方式重新启动Windows资源管理器进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!