[Bug] Npp loses all open files after restarting as Admin
-
@Gilad-D said in [Bug] Npp loses all open files after restarting as Admin:
@PeterJones
Thanks for the tips, and sorry about posting a bug in the wrong place. I actually tried looking around the forums and this seemed the most suitable one, but of course I should have RTFM first…None of the Forum categories. As the FAQ says, the Developer will only see requests on the GitHub Issues.
The Forum, on the other hand, is good for finding workarounds, like the one I suggested.
I don’t really need to have two instances of NPP running, one with Admin rights and one without. I prefer it to only have one instances, with Admin rights by default. The question is can I do that not just for a specific shortcut but also when opening NPP by double-clicking a text file, for example.
In Windows registry, you can do just about anything, with some effort – especially if you’re still on Windows 10 (as your DebugInfo above showed). Googling for “regedit elevated privilege verb” or other such phrases would probably help – and if nothing else, you could just create a verb on the
*
filetype which has a command based on my suggested Run>Run command – you would use the full path to notepad++ instead of the$(NPP_FULL_FILE_PATH)
variable, and the%1
argument (which is what registry uses for passing the filename to the verb’s command) -
@PeterJones
Thanks for the tips. I think that by editing the main shortcut I’m using to have Admin privileges it solved the issue, but I’ll keep an eye out for it. It would be good to make the restart process more stable, though. It it ever happens again I will report it as a bug on GitHub. -
@Gilad-D said in [Bug] Npp loses all open files after restarting as Admin:
This just happened to me, and it’s a really dangerous bug, as it causes all unsaved work to be totally lost
You are right.
Notepad++ is full of features that were born from cries of lazy users.
It is great to listen to customers, but complaints should be analyzed to a root-cause. For proposed solutions risks should be evaluated and integration should maintain coherency of the product.Notepad++ solutions are too often a hurried patch, aimed at the specific user cries with too little regard to other users. It turns the product into a kludge.
This open-as-admin is a prime example.
-
@Gilad-D
I cannot reproduce your issue, all my unsaved files are still opened in N++ after such admin-mode restart. I tried several times even with your “-multiInst” cmdline param.Notepad++ v8.6.2 (64-bit)
Build time : Jan 14 2024 - 02:16:00
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line : -multiInst
Admin mode : ON
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Enterprise LTSC 2021 (64-bit)
OS Version : 21H2
OS Build : 19044.3930
Current ANSI codepage : 1250
Plugins :
mimeTools (3)
NppConverter (4.5)
NppExport (0.4)@gstavi
It is more a matter of different philosophy. That N++ coding style is called (bio)organic coding.What you are (probably) calling for is some constructional coding style where everything is planned and not created ad hoc.
Both styles have their pros and cons. For smaller projects/teams the organic is IMO much better (e.g. much closer to the KISS principle, no unused-code, etc). The N++ project just evolved and now it is not quite so small. And as with most older projects, there are now some major design flaws that no one anticipated when this app was created.
Who knows - maybe like every organic species, it has to die one day. But I hope its time has not come yet ;-)
-
Another issue for Notepad++ is that it uses Scintilla for the editor, Boost for searching, plus an open source package installer. Within a package a developer has the freedom to rewrite things to clean then up but is constrained by the edges which are interfaces to the user, existing configuration data file locations/formats, interfaces to/with other packages, and the interface with Windows.
That all said, I and others are still trying to figure out if and how to reproduce the issue you observed and reported. For starters, I see that you are using
-multiInst
but not-settingsDir
or-nosession
. That means all your instances will be sharing the same set of configuration files and sharing theSession.xml
file. Notepad++ loads the files when you start a copy and writes them back when you close/exit Notepad++. Thus, your issue may have been triggered by the order that you started and exited instances. I have no idea how well or badly Notepad++'s backup folder management code works when you have multiple instances sharing the same sessions and backup folder.FWIW, both
-settingsDir
and-nosession
and Notepad++ are band-aid fixes to someone’s issue and was not part of a long term design for an editor that would work seamlessly in a wide variety of configurations. Microsoft is also struggling with similar issues and their band-aid efforts have been over the years to add %AppData%, %ProgData%, roaming profiles, virtual and shadow folders, etc. -
@mkupper said in [Bug] Npp loses all open files after restarting as Admin:
I have no idea how well or badly Notepad++'s backup folder management code works when you have multiple instances sharing the same sessions and backup folder.
It doesn’t work all that well…
If you have 2 instances, each with a
new 1
soft file, they will both be backed up into the same folder location on disk.Configuration files, e.g.
config.xml
are written by the last instance exited – this has been discussed in this forum many times before. (Not sure about what happens with thesession.xml
file; I didn’t investigate.) -
@Alan-Kilborn said in [Bug] Npp loses all open files after restarting as Admin:
If you have 2 instances, each with a new 1 soft file, they will both be backed up into the same folder location on disk.
A collision seems very unlikely. I was writing about the files in the
%AppData%\backup
folder. Anew 1
file gets saved using a file name that looks likenew 1@2024-02-02_164529
where2024-02-02_164529
is the date/time the backup file is created. Notepad++ then refreshes the backup every seven seconds.For there to be a collision you would need to create two or more
new 1
files within one second, or to make the first change to two different files with the same name (but different paths) within one second. In thinking about it, the more likely collision that would loose all files is the session.xml files.The odds are high that @gstavi’s lost files are in the shared backup folder and are all up to date with no loss data. Normally, Notepad++ is good at automagically retrieving your unsaved data from the backup folder but it depends on the session.xml file to do this.
-
@mkupper said in [Bug] Npp loses all open files after restarting as Admin:
A collision seems very unlikely. A new 1 file gets saved using a file name that looks like new 1@2024-02-02_164529 where 2024-02-02_164529 is the date/time the backup file is created. Notepad++ then refreshes the backup every seven seconds.
A collision is certain. Did you try firing up two instances and having a
new 1
(soft-named) file in each, and watch the backup directory as you change text in each instance? Only one backup file is created and maintained.Interestingly, however, if you create a hard-named file in the file system, and open that in each instance, and watch the backup directory, two files are created and maintained.
Experiments conducted with N++ 8.6.2.
-
@Alan-Kilborn said in [Bug] Npp loses all open files after restarting as Admin:
A collision is certain. Did you try firing up two instances and having a new 1 (soft-named) file in each, and watch the backup directory as you change text in each instance? Only one backup file is created and maintained.
I actually discovered this a while back, and Don Ho’s response (which I think makes sense) was that
NPPM_INTERNAL_SETFILENAME
(which AFAIK is the only way to get two files with the same “soft” name) is not something that plugins are supposed to use. -
@Mark-Olson said in [Bug] Npp loses all open files after restarting as Admin:
(which AFAIK is the only way to get two files with the same “soft” name)
My discussion in this thread is about two instances running. In this situation, one can easily have two soft-named files with the name
new 1
simultaneously – one in each instance.I’m not saying I care…much. I don’t use soft-named files (ever) and I don’t use multiple instances of the same Notepad++ (ever), but I thought it might be interesting to investigate at a user-level how the backup system in Notepad++ works in such a case, based upon @mkupper 's first comment in this thread.
-
Thanks everyone for the thought provoking comments here. I think I am now able to simulate the problem reported. And I have some answers to how the N++ backup feature works at these circumstances (had some fun with debugging of multiple instances of the same app in the same dir … )
There is no possible backup collision in between that two N++ multi-inst instances because that N++ backup feature will only work for the 1st instance and not for the other ones. Here is a backtrace why:
In short - the following winmain.cpp code (setting the cmdLineParams._isNoSession to true because it is not TheFirstOne) results also in not activating the backup function in any non-1st N++ instance at the end:
if (nppGUI._multiInstSetting == multiInst) { isMultiInst = true; // Only the first launch remembers the session if (!TheFirstOne) cmdLineParams._isNoSession = true; }
So to reproduce the OP’s issue:
- set the N++ multi-instance mode (either via the Preferences > Multi-Instance & Date > Muti-instance settings == Always… or via the “-multiInst” cmdline param) & restart N++
- open 1st instance of N++ (this one will have the N++ backup feature working)
- launch the 2nd one, create there some unsaved tabs with data, then try to open-edit-save a file in a restricted folder (e.g. in C:\Windows\) in it
- click Yes in the “Do you want to launch N++ in admin-mode?” msgbox
- 3rd N++ instance (now with admin-rights) will be opened but there will not be the unsaved/unbackuped file-tabs form the previous 2nd instance, see the pic
I am not saying that this is all an optimal behavior but a data loss reported here is possibly caused only by a user hands (probably closing of the 2nd unbackuped multi-inst N++) and not by a N++ code failure.
@PeterJones
I quickly checked the N++ user manual and there is not(?) an explicit note about such multi-inst setup influencing that backup feature in the way I described. If so, could you please add a short note both in the Preferences “Multi-Instance and Date” and in the “Backup” sections? I mean e.g. something like “Warning: The Notepad++ backup feature in multi-instance setups will work only for the 1st Notepad++ instance.” -
@xomx said in [Bug] Npp loses all open files after restarting as Admin:
if so, could you please add a short note
-
@xomx said :
There is no possible backup collision in between that two N++ multi-inst instances because that N++ backup feature will only work for the 1st instance and not for the other ones
This seems to go against what I was seeing in my earlier statements.
Perhaps my experiments were invalid because my setting was always “mono-instance” and I was opening two instances of the same Notepad++ with the-multiInst
command line parameter… -
@Alan-Kilborn
Right you are, it is even more complicated.
N++ Preferences setting and the cmdline-multiInst
is not equivalent, this is a mess!So what I wrote previously above only applies to the Preferences setting, with the cmdline setting the N++ backup function is also enabled on other N++ instances and they “happily” overwrite each other’s “new 1” documents backups (I tested). This definitely needs a fix!
-
Issue (& PR for testing):
https://github.com/notepad-plus-plus/notepad-plus-plus/issues/14691 -
This seems similar:
https://github.com/notepad-plus-plus/notepad-plus-plus/issues/14694
-