如何以编程方式重新启动 Windows 资源管理器进程 [英] How to programmatically restart windows explorer process

查看:21
本文介绍了如何以编程方式重新启动 Windows 资源管理器进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 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?

附言我意识到我可以去任务管理器并杀死资源管理器进程,但我只想以懒惰的方式来做.此外,这可以实现自动化.

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 进行开发,但外壳重启功能可以是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆