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

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

问题描述

我工作的一个Windows外壳扩展,不幸的是,在更改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).

我发现这个节目从恐龙埃斯波西托,但它不为我工作。

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。我意识到,我可以去任务管理器,杀死Explorer进程,但我只是想做到这一点偷懒的方法。此外,这使得自​​动化。

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.

PPS我使用.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.

推荐答案

一个很简单的解决方案:

A fool-proof solution:

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天全站免登陆