How to correctly unload C ++ shell DLL extension

I have a dll shell extension written in C ++ and the COM DLL is registered and loaded into memory. My update installer will do the following:

  • Unregister shell dll, kill explorer.exe
  • Copy a later shell dll shell (step 2)
  • Run t explorer.exe

It works great. But the problem is this:

If the user has opened other applications (Internet Explorer, sometimes window manager, notepad, etc.), Step 2 does not work.

Is there a way to close all DLL shells with shell extension when updating dll.

In dll, I use GetOverlayInfo, context menu, database connection, etc.

+6
source share
2 answers

Simply put: do not do this (i.e. do not force unload it). You will need to list all the processes in which the shell extension is loaded, and then restart them. This is very invasive and frank: bad behavior (for the installer). It also requires special privileges that your installer may not need.

What most people still don't know is that MoveFile (and MoveFileEx ) can be used to move the DLL or EXE files that are currently being used by a running application.

This is the approach that Windows Installer takes. Have you ever noticed the \Config.msi folder in the root directory of this drive after installing some .msi ? This folder actually contains (moves and is usually renamed to some unique β€œtemporary” name) source files that were moved but were still in use at that time. Then they are usually assigned for deletion at boot ( MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT ).

You can use the same mechanism in your homebrew installer and transfer the old file that is used in the original location and transfer the other immediately. Any new application instance will use 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.

(*) I am not 100% sure about this because of the rules that apply to loading DLLs, and do not allow loading modules with the same name under certain circumstances.

+7
source

Depending on your installer, you may use Restart Manager support in Windows Vista +. This will allow your installation to query for every application using your DLL, and try and gracefully close them. If they cannot be, then you will need to register it for a replacement at restart. After completing the setup, Restart Manager will try to restart all the programs that it has disabled (support restarts).

+1
source

Source: https://habr.com/ru/post/919871/


All Articles