Community
    • Login

    [Bug] Npp loses all open files after restarting as Admin

    Scheduled Pinned Locked Moved General Discussion
    bugcrashadmin rights
    20 Posts 8 Posters 1.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Gilad DG
      Gilad D
      last edited by

      This just happened to me, and it’s a really dangerous bug, as it causes all unsaved work to be totally lost! I typically have to restart NPP when saving files in some folders that require admin access, which is annoying but not a major deal, but not when it happened NPP re-opened without all of my previously opened files, AND all non-saved files were closed without saving!

      I get this dialog when I try to save such files:

      bc7e1158-0b1c-4621-94a4-984eb076dd02-image.png

      I would really like to see this issue resolved, as it’s quite a scary thing to happen! I rely on NPP’s excellent feature of restoring non-saved files when I launch it, but I won’t be able to do that if they can get lost so easily…

      NPP debug info:
      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 Pro (64-bit)
      OS Version : 22H2
      OS Build : 19045.2486
      Current ANSI codepage : 1252
      Plugins :
      ComparePlugin (2.0.2)
      JSMinNPP (1.2312)
      mimeTools (3)
      NppConverter (4.5)
      NppExport (0.4)
      NppFavorites (1.0.0.1)
      XMLTools (3.1.1.13)

      PeterJonesP 1 Reply Last reply Reply Quote 1
      • PeterJonesP
        PeterJones @Gilad D
        last edited by PeterJones

        @Gilad-D ,

        Relying on the session-and-periodic-backup “unsaved files” feature while switching from normal to Admin mode may not be wise. (The “unsaved files” feature seems to have been meant more as a “we’ll try to help you if something goes unintentionally wrong, but no guarantees”, not a “we’ll guarantee you keep unsaved files forever so you should definitely rely on this feature as part of your normal workflow”… but I digress.)

        If you are frequently doing Admin-mode edits with Notepad++, I actually suggest creating a second shortcut to Notepad++: it would have Advanced > Run as Administrator turned on, and it would have the command-line options -multiInst -nosession
        3553b6f1-d9b6-44f9-a23b-4a6b5fdaedb1-image.png
        That way, you would run that shortcut (which could be pinned to your taskbar if you wanted) and then open the admin-needed file in the second instance, and the admin instance doesn’t interfere with the active session in the normal instance (and, in fact, leaves the current Notepad++ alone completely, and even allows it to still be running)

        As another option, from a normal Notepad++ Run > Run dialog, the command powershell -Command "Start-Process '$(NPP_FULL_FILE_PATH)' -ArgumentList '-multiInst -nosession "$(FULL_CURRENT_PATH)"' -Verb runAs" will run a second instance of Notepad++ which is in Admin mode with the multi-instance/no-session options. So if you try to edit the file in normal Notepad++, and it complains, you can cancel the “reopen in Admin” which messes up your session, and instead, launch that Run > Run command (which you could save with a name, and even give a keyboard shortcut to), and it would spawn a second Notepad++ in Admin mode for editing just that file. You could then even copy your unsaved changes from the normal Notepad++ to the Admin Notepad++, and do the save in the Admin instance.

        ----

        Update: BTW: this forum isn’t where bug reports go: see our FAQ.

        Gilad DG 1 Reply Last reply Reply Quote 3
        • Gilad DG
          Gilad D @PeterJones
          last edited by

          @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…

          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.

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @Gilad D
            last edited by

            @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)

            Gilad DG 1 Reply Last reply Reply Quote 0
            • Gilad DG
              Gilad D @PeterJones
              last edited by

              @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.

              1 Reply Last reply Reply Quote 0
              • gstaviG
                gstavi
                last edited by

                @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.

                xomxX 1 Reply Last reply Reply Quote 2
                • xomxX
                  xomx @gstavi
                  last edited by

                  @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 ;-)

                  mkupperM 1 Reply Last reply Reply Quote 3
                  • mkupperM
                    mkupper @xomx
                    last edited by

                    @gstavi

                    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 the Session.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.

                    Alan KilbornA 1 Reply Last reply Reply Quote 1
                    • Alan KilbornA
                      Alan Kilborn @mkupper
                      last edited by

                      @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 the session.xml file; I didn’t investigate.)

                      mkupperM 1 Reply Last reply Reply Quote 0
                      • mkupperM
                        mkupper @Alan Kilborn
                        last edited by mkupper

                        @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. 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.

                        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.

                        Alan KilbornA 1 Reply Last reply Reply Quote 1
                        • Alan KilbornA
                          Alan Kilborn @mkupper
                          last edited by

                          @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.

                          Mark OlsonM 1 Reply Last reply Reply Quote 1
                          • Mark OlsonM
                            Mark Olson @Alan Kilborn
                            last edited by

                            @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.

                            Alan KilbornA 1 Reply Last reply Reply Quote 0
                            • Alan KilbornA
                              Alan Kilborn @Mark Olson
                              last edited by

                              @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.

                              1 Reply Last reply Reply Quote 1
                              • xomxX
                                xomx
                                last edited by

                                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:

                                https://github.com/notepad-plus-plus/notepad-plus-plus/blob/5e6df259423680f82e98e42af31c996690a06e26/PowerEditor/src/Notepad_plus_Window.cpp#L403-L409

                                https://github.com/notepad-plus-plus/notepad-plus-plus/blob/5e6df259423680f82e98e42af31c996690a06e26/PowerEditor/src/Parameters.h#L916

                                https://github.com/notepad-plus-plus/notepad-plus-plus/blob/5e6df259423680f82e98e42af31c996690a06e26/PowerEditor/src/Notepad_plus_Window.cpp#L93

                                https://github.com/notepad-plus-plus/notepad-plus-plus/blob/5e6df259423680f82e98e42af31c996690a06e26/PowerEditor/src/winmain.cpp#L529-L535

                                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

                                npp-mutliinst-admin-test.png

                                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.”

                                PeterJonesP Alan KilbornA 2 Replies Last reply Reply Quote 1
                                • PeterJonesP
                                  PeterJones @xomx
                                  last edited by

                                  @xomx said in [Bug] Npp loses all open files after restarting as Admin:

                                  if so, could you please add a short note

                                  Added ⇒ backup section and Multi-Instance section

                                  1 Reply Last reply Reply Quote 2
                                  • Alan KilbornA
                                    Alan Kilborn @xomx
                                    last edited by

                                    @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…

                                    xomxX 1 Reply Last reply Reply Quote 1
                                    • xomxX
                                      xomx @Alan Kilborn
                                      last edited by xomx

                                      @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!

                                      xomxX 1 Reply Last reply Reply Quote 1
                                      • xomxX
                                        xomx @xomx
                                        last edited by

                                        Issue (& PR for testing):
                                        https://github.com/notepad-plus-plus/notepad-plus-plus/issues/14691

                                        Alan KilbornA 1 Reply Last reply Reply Quote 1
                                        • Alan KilbornA
                                          Alan Kilborn @xomx
                                          last edited by

                                          This seems similar:

                                          https://github.com/notepad-plus-plus/notepad-plus-plus/issues/14694

                                          1 Reply Last reply Reply Quote 0
                                          • donhoD
                                            donho
                                            last edited by

                                            Fixed in https://github.com/notepad-plus-plus/notepad-plus-plus/commit/76cfc5945ecf1bebabb52a032572ec7f6b7b6029

                                            1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors