如何正确卸载C ++ Shell Extension DLL [英] How to unload C++ Shell Extension DLL properly

查看:664
本文介绍了如何正确卸载C ++ Shell Extension DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用C ++和COM编写的 shell扩展dll 该dll已注册并加载到内存中.我的升级设置程序将执行以下操作:

I have shell extension dll written in C++ and COM The dll is registered and loaded into memory. My upgrade setup program will do the following:

  • 取消注册外壳扩展dll,杀死explorer.exe
  • 复制更高版本的Shell扩展dll(第2步)
  • 开始explorer.exe

工作正常.但是问题是:

It works fine. But the issue is:

如果用户打开了其他任何应用程序(Internet Explorer,有时是Windows任务管理器,记事本等),则步骤步骤2 将失败.

If the user opened any other applications ( Internet explorer, sometimes windows task manager, notepad etc), the step Step 2 is failing.

在升级dll时,有没有办法关闭所有shell扩展dll钩子.

Is there any way to close all shell extension dll hooks while upgrading the dll.

在dll中,我正在使用GetOverlayInfo,上下文菜单,数据库连接等

In the dll I am using GetOverlayInfo, context menu, database connection etc

推荐答案

简单地说:不要这样做(即不要强行卸载它).您必须枚举具有以下特征的所有进程:您的Shell扩展已加载,然后重新启动"那些扩展.这非常具有侵入性,并且很坦率地说:不良行为(对于安装程序而言).这还需要安装程序 可能不需要的特定特权.

Simply put: don't do it (i.e. do not unload it forcibly). You would have to enumerate all processes that have your shell extension loaded and then "restart" those. This is very invasive and quite frankly: bad behavior (for an installer). This also requires particular privileges which your installer may not otherwise need.

大多数人似乎仍然不知道的是,MoveFile(和MoveFileEx)可用于通过运行来移动当前正在使用的DLL或EXE文件 .应用程序.

What most people still don't seem to be aware of is that MoveFile (and MoveFileEx) can be used to move DLLs or EXE files that are currently in use by a running application.

这是Windows Installer采取的方法.在安装某些.msi之后,您是否曾经注意到给定驱动器根目录中的\Config.msi文件夹吗?此文件夹实际上包含(已移动并通常重命名为某些唯一的临时"名称)已移出但仍在使用中的原始文件.然后通常安排它们在引导时删除(MoveFileExMOVEFILE_DELAY_UNTIL_REBOOT).

This is the approach Windows Installer takes. Have you ever noticed the folder \Config.msi in the root of a given drive after installing some .msi? This folder actually contains (moved and usually renamed to some unique "temporary" name) the original files that have been moved out but were still in use at the time. They are then usually scheduled for deletion upon boot (MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT).

您可以在自制软件安装程序中使用相同的机制,然后将正在使用的旧文件移出其原始位置,然后立即移走另一个文件.然后,任何新的应用程序实例都将使用新的外壳程序扩展名(*),而旧的外壳程序扩展名将继续由在某个时间点或另一点加载它的任何正在运行的应用程序使用.

You can use the same mechanism in your homebrew installer and move the old file that is in use out of its original location and move the other one in right away. Any new application instance will then make use of the new shell extension (*), while the old one will continue to be used by any of the running applications that loaded it at one point or another.

(*)我不确定100%的原因,因为适用于DLL加载的规则会阻止在某些情况下再次加载同名的模块.

(*) I'm not 100% sure about this because of the rules that apply to DLL loading and prevent modules with the same name to be loaded again under some circumstances.

这篇关于如何正确卸载C ++ Shell Extension DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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