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

N++ (run as administrator) minimized window doesn't restore when opening a file using the “Edit with Notepad++” context menu option #13041

Closed
przemo20 opened this issue Feb 3, 2023 · 26 comments
Assignees

Comments

@przemo20
Copy link
Contributor

przemo20 commented Feb 3, 2023

Description of the Issue

If you open Notepad++ as an administrator, minimize it, right-click on any file and choose the “Edit with Notepad++” context menu option, you will see in the Windows taskbar that Notepad++ window is now active, but it didn't get restored. You have to click on the Notepad++ icon to bring up its window to see the file you just opened. This works normally if you run N++ WITHOUT admin rights.

Video: https://www.youtube.com/watch?v=AxUyqAJEk0k

Steps to Reproduce the Issue

  1. Run Notepad++ as an administrator
  2. Minimize Notepad++ window
  3. Right-click on any file and select the “Edit with Notepad++” option from the context menu that shows up

Expected Behavior

After selecting the “Edit with Notepad++” option, Notepad++ window should be set to active and open up.

Actual Behavior

After selecting the “Edit with Notepad++” option, Notepad++ window gets set to active, BUT doesn't open up.

Debug Information

Notepad++ v8.4.9   (64-bit)
Build time : Jan 27 2023 - 03:11:16
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line : "C:\Users\Przemo\Desktop\Test.txt"
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 : 1250
Plugins : 
    ComparePlus (1.1)
    mimeTools (2.9)
    NppConverter (4.5)
    NppExport (0.4)
@alankilborn
Copy link
Contributor

In step 3, where is this right-clicked file originating?
The reason for my question is that if the source is NOT an "admin" source, should an "admin" Notepad++ even accept the file?

Consider drag-and-drop of a file from a "non-admin" Explorer instance to an "admin" Notepad++ instance -- it doesn't work (because the permissions are different).

@przemo20
Copy link
Contributor Author

przemo20 commented Feb 3, 2023

Yeah, just tested it and it's just as you say (meaning the drag-and-drop feature doesn't work if Notepad++ is run as an administrator on non-Super Administrator account; not sure though what you mean by the source is NOT an "admin" source, I tried with different files, like from the C:\Windows directory, hidden files, opening Windows Explorer as administrator and then using the drag-and-drop feature, and that didn't work either – anyway, that's not important), but I think that IS NOT the case here. As you can see even on my recording, the file I opened using the “Edit with Notepad++” option DID indeed open – it's just that the Notepad++ window stays minimized. That should cross out permissions are different, I guess?

@alankilborn
Copy link
Contributor

not sure though what you mean by the source is NOT an "admin" source

I meant, e.g. if you are dragging from an Explorer window that is not run-as-admin, and you try dropping into an admin N++ window, it won't work. Drag and drop admin-to-admin should work, however, I'd think, hmm. But you're right, that isn't the issue you're describing. I wasn't saying it was, I was just wondering if some of the same elements were coming into play for your issue.

... That should cross out permissions are different, I guess?

Well, unless the bug you describe shouldn't happen because it shouldn't even get that far (meaning a bug happens before your described bug).

I'm not a permissions expert, I was just curious what permission level the "Edit with Notepad++" thing runs at. If it is coming from an Explorer window, it's got to be the same as that instance of Explorer.

I'll move on, now. :-)

@Yaron10
Copy link

Yaron10 commented Feb 5, 2023

@donho & @robotboy655,

I've tested it with different Windows permissions, and could reproduce it.
The regression is caused by afacc83.

@robotboy655
Copy link
Contributor

@donho Easy enough to fix, adding

// Allow non admin NP++ to send this message to admin NP++ mono instance
ChangeWindowMessageFilter( NPPM_INTERNAL_RESTOREMONOINSTANCE, MSGFLT_ADD );

Somewhere in WinMain (for example in Notepad_plus_Window::init) will solve this in my tests. The issue is that non admin apps are not allowed to send custom messages to admin apps by default.

@alankilborn
Copy link
Contributor

The issue is that non admin apps are not allowed to send custom messages to admin apps by default.

@przemo20 This was what I was getting at.

@donho
Copy link
Member

donho commented Feb 5, 2023

I cannot reproduce the bug, but in admin mode when Notepad++ is reduced in system tray, open a file via "Edit with Notepad++", I've got Notepad++ opened with the file, but opened panel is disappeared.

I followed the suggestion of @robotboy655 in #13058 and my problem has been fixed.

Could you guys confirm me that #13058 has fixed your bug as well please? (Copying the binary into C:\Program File\Notepad++\ is needed).

@Yaron10
Copy link

Yaron10 commented Feb 6, 2023

@donho,

Unfortunately #13058 does not fix the issue.

I cannot reproduce the bug, but in admin mode when Notepad++ is reduced in system tray...

I'm using the portable version, and I've manually associated some files with NPP.
On my Windows 10 machine I have "super permissions" and therefore I haven't encountered the problem.
On my Windows 7 machine I have "normal permissions" and the issue exists.

Here are my STR:
The setting Minimize to System Tray is unchecked (OFF).
Open NPP.
In Windows TaskBar activate an Explorer Window containing a file associated with NPP.
Double-click on that file.

Result:
The file is opened in NPP.
NPP does not come to the foreground but remains blinking in the TaskBar.

I suppose it can be reproduced on Windows 10 as well (with "normal permissions").

Thank you for your work. I appreciate it. 👍


Notepad++ v8.4.9 (32-bit)
Build time : Feb 5 2023 - 23:54:18
Path : C:---notepad++.exe
Command Line : "C:---\Test.xul"
Admin mode : ON
Local Conf mode : ON
Cloud Config : OFF
OS Name : Windows 7 Enterprise (32-bit)
OS Build : 7601.23964
Current ANSI codepage : 1255
Plugins :
ComparePlus (1.1)
HTMLTag (1.3.6)
MenuIcons (2.0.2)
PythonScript (1.5.4)
_CustomizeToolbar (4.2)

@donho
Copy link
Member

donho commented Feb 6, 2023

@Yaron10
Thank you for your detail explanation.
I believe the bug is fixed (just done a new commit). Could you validate the fix please?

@Yaron10
Copy link

Yaron10 commented Feb 6, 2023

@donho,

The new commit does fix the issue. 👍

Actually, just moving ::SetForegroundWindow() back to winmain.cpp solves the problem.

That is, the only change to afacc83 can be removing ::SetForegroundWindow(hwnd); from NppBigSwitch.cpp and adding ::SetForegroundWindow(hNotepad_plus); after ::SendMessage(hNotepad_plus, NPPM_INTERNAL_RESTOREMONOINSTANCE, 0, 0); in winmain.cpp.

What do you think?

Thank you.


@przemo20,

Could you please test the binary in https://ci.appveyor.com/project/donho/notepad-plus-plus/builds/46146526/job/5ft8k80cr1q65onb/artifacts on your machine?

This might be important:
Delete/rename your current notepad++.exe and rename Notepad++.x64.Release.exe to notepad++.exe.

Thank you.

@przemo20
Copy link
Contributor Author

przemo20 commented Feb 6, 2023

Err... for me is the other way around (or I'm doing something wrong; also I can't redowload the files to check them again, because of the Artifacts download limit (1024 MB/day) exceeded. error). The 1st fix works fine, while the 2nd one – does not, it even breaks it more [specifically on the Windows 11 VM I can't restore the Notepad++ window after using the “Edit with Notepad++” option | Video: https://youtu.be/d6AikYRauVQ]. This is based on my testing on Windows 10 x64, Windows 11 x64 (VM) and Windows 7 x32 (VM and on the 32-bit version of Notepad++ + 32-bit executable from appveyor).

1st fix (64-bit; Release) Build time : Feb 6 2023 - 00:10:55
2nd fix (64-bit; Release) Build time : Feb 6 2023 - 02:22:09

@Yaron10
Copy link

Yaron10 commented Feb 6, 2023

@przemo20,

Thank you for testing and replying.

I just want to make sure: the problem does NOT occur with Notepad++ v8.4.8, does it?

@sXNA
Copy link

sXNA commented Feb 6, 2023

for me the first worked, second I cannot test, because of "Artifacts download limit (1024 MB/day) exceeded" error.

Interesting is that I have to renamed it to "notepad++.exe" if I have another notepad++ in different location, and it is already opened and minimized to bring it foreground. If not renamed it stay minimized but tab is opened.

@Yaron10
Copy link

Yaron10 commented Feb 6, 2023

@sXNA,

Same question to you: did you have any problem with Notepad++ v8.4.8?

@Yaron10
Copy link

Yaron10 commented Feb 6, 2023

{"message":"Artifacts download limit (1024 MB/day) exceeded."}.
That's a new one. :)

@przemo20
Copy link
Contributor Author

przemo20 commented Feb 6, 2023

@przemo20,

Thank you for testing and replying.

I just want to make sure: the problem does NOT occur with Notepad++ v8.4.8, does it?

Seems like this was a problem always. I have installed the version 8.4.8 on a Win 10 VM and this doesn't work either. Then tried version 8.4.7, 7.5.6 and 6.2.3 – still nothing.

@sXNA
Copy link

sXNA commented Feb 6, 2023

@Yaron10
I downloaded portable 8.4.8 and it does not work.

@Yaron10
Copy link

Yaron10 commented Feb 6, 2023

@przemo20,

Seems like this was a problem always.

Is it likely you would not have noticed such a problem earlier?

I have installed the version 8.4.8 on a Win 10 VM and this doesn't work either.

Did you still have v8.4.9 on that machine?

@Yaron10
Copy link

Yaron10 commented Feb 6, 2023

@sXNA,

So we might have two different issues here. Let's wait for @donho's reply.

@przemo20
Copy link
Contributor Author

przemo20 commented Feb 6, 2023

Is it likely you would not have noticed such a problem earlier?

Yes, that's correct. About 2 weeks ago I switched from Windows 7 to Windows 10 and I started seeing this problem after setting Notepad++ shortcut to always run with administrator privileges. On Windows 7 I have had UAC disabled so I didn't need to do this – Notepad++, explorer.exe, cmd etc. were always starting as an administrator.

Did you still have v8.4.9 on that machine?

I uninstalled v8.4.9 before installing v8.4.8.

@donho
Copy link
Member

donho commented Feb 6, 2023

Actually, just moving ::SetForegroundWindow() back to winmain.cpp solves the problem.

That is, the only change to afacc83 can be removing ::SetForegroundWindow(hwnd); from NppBigSwitch.cpp and adding ::SetForegroundWindow(hNotepad_plus); after ::SendMessage(hNotepad_plus, NPPM_INTERNAL_RESTOREMONOINSTANCE, 0, 0); in winmain.cpp.

What do you think?

@Yaron10
IMO, my 2nd fix is afacc83 should be for the minimum impact. So I prefer to keep it this way.

@Yaron10
Copy link

Yaron10 commented Feb 6, 2023

@przemo20,

Yes, that's correct. About 2 weeks ago...

👍

@donho,

IMO, my 2nd fix is afacc83 should be for the minimum impact. So I prefer to keep it this way.

👍

So, @przemo20's & @sXNA's issue is not related to afacc83 at all.

@donho
Copy link
Member

donho commented Feb 6, 2023

@Yaron10

So we might have two different issues here. Let's wait for @donho's reply.

I have no idea about the 2nd eventual issue.

I have had the bring foreground issue (cannot reproduce steadily though) and Panel disappear issue (with tray).
Both issues are fixed by #13058 - it's strange for me that v8.4.8 has the same issue.
Since we cannot download the fixed binaries from CI of #13058, and the builds of Appveyor is quite long, plus I've confidence about my fix, I will merger PR 13058 into master. We will report any issue based on the master - it'll be the simplest way.

@Yaron10
Copy link

Yaron10 commented Feb 6, 2023

@donho,

I will merger PR 13058 into master. We will report any issue based on the master - it'll be the simplest way.

👍
Thanks again for your time and work.

@donho donho closed this as completed in 39f32bd Feb 6, 2023
@przemo20
Copy link
Contributor Author

przemo20 commented Mar 9, 2023

Hi. Could you reopen this issue as it wasn't fixed? I still can reproduce it in Notepad++ v8.5.

As I already stated in one of my previous comments (#13041 (comment)), the first fix from Don (donho@adb2c7f) fixed the issue for me.

Here're some alternative steps to reproduce the issue (maybe those will be easier).

Alternative Steps to Reproduce the Issue

  1. Run Notepad++ as an administrator
  2. Minimize Notepad++ window
  3. Open Command Prompt (NOT as an administrator) and go to the location where you installed N++
    (cd "C:\Program Files\Notepad++" by default)
  4. Type "notepad++.exe" readme.txt and press Enter

Video: https://www.youtube.com/watch?v=BZBOjsw5X7Q

Debug Information (from the VM that I recorded the above video)

Notepad++ v8.5   (64-bit)
Build time : Mar  6 2023 - 02:18:13
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line : readme.txt
Admin mode : ON
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Pro (64-bit)
OS Version : 22H2
OS Build : 19045.2604
Current ANSI codepage : 1252
Plugins : 
    mimeTools (2.9)
    NppConverter (4.5)
    NppExport (0.4)

@havrlisan
Copy link

I can confirm the issue persists in v8.5.1. I have done the same steps as @przemo20, and got the same result.

Notepad++ v8.5.1   (64-bit)
Build time : Mar 21 2023 - 19:16:10
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line : 
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 11 Pro (64-bit)
OS Version : 22H2
OS Build : 22621.1485
Current ANSI codepage : 1252
Plugins : 
    HexEditor (0.9.12)
    mimeTools (2.9)
    NppConverter (4.5)
    NppExport (0.4)
    NppFavorites (1.0.0.1)
    NPPJSONViewer (2.0.4)
    PreviewHTML (1.3.2)
    XMLTools (3.1.1.13)

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

Successfully merging a pull request may close this issue.

7 participants