Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NppShell.dll is not released after N++ uninstall #66

Open
pawelzwronek opened this issue Dec 3, 2024 · 18 comments
Open

NppShell.dll is not released after N++ uninstall #66

pawelzwronek opened this issue Dec 3, 2024 · 18 comments

Comments

@pawelzwronek
Copy link

While investigating notepad-plus-plus/notepad-plus-plus#15892 I found NppShell.dll is not released after N++ uninstallation, and after a fresh installation in e.g. c:\Program Files RMB Explorer contex menu is not working because old dll is loaded like so:

obraz

Running regsvr32.exe /s /u ... as admin also didn't help.

@PGomersall
Copy link

OK, some more info.
It seems that the uninstall "sometimes" works. It uninstalled correctly on a Server running Windows Server 2025 (basically W11 server 24H2) with only one logged on user.
On the server I found the issues on, that was Server 2022 ( W10 server ) and there were other users logged on which probably caused the inability to remove the dll.
Not sure if there is any difference cause by W10 or W11, the dll does work differently I believe between the 2.

@GurliGebis
Copy link
Contributor

There is no safe way to unload a DLL from explorer (except terminating the process) - so there isn't really anything we can do.
There are some hack around - but there is no safe way to do it.

@pawelzwronek
Copy link
Author

Is it possible that NppShell.dll keeps opened some resources/handlers which block it from unloading when regsvr32.exe /s /u ... is executed?

@GurliGebis
Copy link
Contributor

No, but like I said, there is no safe way to unload it from explorer.exe .
So even though it has no handles to any files open, it is still loaded into explorer until explorer restarts.

@pawelzwronek
Copy link
Author

So explorer even is not trying to unload it on regsvr32.exe /s /u ... ?

@GurliGebis
Copy link
Contributor

I did try to add it, the only thing that happens if you try to unload it, is that explorer.exe will crash (due to the thread running the code dying), so 🤷‍♂️

@GurliGebis
Copy link
Contributor

The only thing that does is just call a function inside the DLL - we would have to implement it ourselves - it doesn't do anything for us, except call a function.
Trying to unload the DLL where your own function resides with will cause the process to crash (like cutting the branch you are sitting on)

@pawelzwronek
Copy link
Author

How about to let the DLL know to be aware of new N++ location? It's only a guess, because I don't know the architecture.

@GurliGebis
Copy link
Contributor

I don't see how that would unload the DLL from the explorer process?

@pawelzwronek
Copy link
Author

I mean, keep the dll loaded, but make it work with new N++ location.

@GurliGebis
Copy link
Contributor

So you are installing notepad++ to a new location, when you are upgrading?

@pawelzwronek
Copy link
Author

I'm not. Just reinstalling: uninstall then install again.

@GurliGebis
Copy link
Contributor

Then the location is the same?
I am a bit confused as to what the issue is.

When the installer updates, it moves the old version away and places the new version in it's place.
Next time explorer starts, it loads the new version.

@pawelzwronek
Copy link
Author

pawelzwronek commented Dec 9, 2024

No. New location is changing. I was testing the issue like this:

  1. Uninstall current version
  2. Install the same version but in new location.

Right now I'm not sure if an old dll is removed or left alone, but the issue is there is no way to unload the dll and load new dll to let it know about new location of N++.

My suggestion was to let loaded dll know about the new location of N++.

(FINAL edition v1 ;)

@GurliGebis
Copy link
Contributor

When you install it, it gets registered in the new location, so it should be loaded from there going forward.

Why do you want to tell the loaded DLL about the new install location?

@pawelzwronek
Copy link
Author

To make Edit with Notepad++ in RMB context menu still works. Now after reinstall to another location, Edit with Notepad++ is showed but nothing happens after clicking it. My idea was that the new location of N++.exe is not updated somewhere, but it's only the guess and I might be wrong.
If I recall right, there is also no N++ icon next to Edit with Notepad++ so maybe the dll is not working anymore, as we discussed earlier and it's futile to update new location of N++ anyway.

@GurliGebis
Copy link
Contributor

That makes sense, since it uses it's own path to find the npp exe.
This is such an edge case, I don't see a good way to fix it.
If you want to work around it, restarting explorer solves the problem.

@whindsaks
Copy link

So explorer even is not trying to unload it on regsvr32.exe /s /u ... ?

Regsvr does not unload anything in other processes, it usually just edits the registry.

Shell extensions can be unloaded in theory when DllCanUnloadNow says so but for this to happen, something inside Explorer has to trigger a call to CoFreeUnusedLibraries and I don't think there is a message you can send to trigger this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants