Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#380 "Insufficient privileges to save" fix

closed
nobody
None
5
2012-06-30
2012-06-08
Andreas Jonsson
No

Currently it's possible to open a file in Notepad++ which requires administrative privileges if you want to save it. When you try to save it, Notepad++ gives you a bad error message ("Please check if this file is opened in another program."). This is a pain since you have to restart the program as administrator.

A process can't elevate itself once it's already been started, so to solve this we need to start another process from Notepad++. My solution works like so:

1) If elevation is needed when saving, Notepad++ first saves the file to a temporary file.
2) A second process - nppcopy.exe - is started with elevated privileges.
3) This second process moves the temporary file to its proper location.

I briefly considered other solutions (i.e. having the second process write the data directly), but IPC using the Windows API seemed very primitive (WM_COPYDATA doesn't handle variable length strings well). My current solution also keeps nppcopy.exe very lightweight and free of dependencies.

The attached zip file consists of:

1) The files needed to build nppcopy.exe.
2) A patch for Notepad++ so that it can take advantage of nppcopy.exe.

Place nppcopy.exe in the same directory as notepad++.exe. I don't know what your release process is, but if you accept this patch you will of course have to include nppcopy.exe in the installer.

I've also included slightly better error messages when saving.

Note that Notepad++ detects that nppcopy.exe has updated the saved file, so it prompts the user to reload the file. This is obviously undesirable. Therefore I disable the autoupdate for one (1) time whenever an elevation is needed (see "skipAutoUpdateOnce" etc).

Discussion

  • nppcopy + patch for Notepad++.

     
    Attachments
  • Fixed bug in nppcopy.

     
    Attachments
  • In the first zip file, nppcopy had a bug (forgot to delete the temp file). This is fixed in "elevate - fixed.zip".

     
  • Don HO
    Don HO
    2012-06-30

    Andreas,

    Thank you for the patch.
    The solution for this "Nice to have" feature is kind of overwhelming to me - That needs a second binary to be included in installer (which makes the installer heavier). And the work around way (another process to elevate the binary) is quite complex - I would suggest user to install the admin shortcut in the installer.

     
  • Don HO
    Don HO
    2012-06-30

    • status: open --> closed