XhmikosR / notepad2-mod

LOOKING FOR DEVELOPERS - Notepad2-mod, a Notepad2 fork, a fast and light-weight Notepad-like text editor with syntax highlighting
https://xhmikosr.github.io/notepad2-mod/
Other
1.45k stars 270 forks source link

Allows to try administrator mode in case of UAC control #78

Open xupefei opened 10 years ago

xupefei commented 10 years ago

Hi, I have made a little improvement to allow Notepad2 run in administrator mode to bypass the UAC control (which makes the file read-only).

First, Notepad2 will try to create a temp file (named like "F9168C5E-CEB2-4FAA-B6BF-329BF39FA1E4") in the target folder. If this is not successful, it will ask for UAC permissions and try again. If it fails again, Notepad2 still opens it, but as read-only.

PS: The rpcrt4.lib required below is for UUID generating.

Hope you like it :)

XhmikosR commented 8 years ago

@xupefei: sorry for the so late answer.

Do you actually use this patch in real life? Does it work OK for you?

mauroservienti commented 8 years ago

Notepad2 will try to create a temp file (named like "F9168C5E-CEB2-4FAA-B6BF-329BF39FA1E4") in the target folder. If this is not successful, it will ask for UAC permissions and try again.

This is non sense. Trying to create a new file is in Noway a good check to see if I can write to another one in the same folder, regardless of UAC or not. I might be able to create a new file but I still might not have permissions to save the original one. Not only I might not have permission to create new files but can edit existing ones. If you don't want to ask the OS for the permissions chains the attempt must be done on the file I'm touching not on another one.

xupefei commented 8 years ago

In real Windows OS the ACL policy is usually applied on dictionaries, not on single file, so test the write permission on the dictionary is (in most cases) also effective for that file. I agree with you that it is better to perform testing on original file, but in that case we need to deal with file timestamp and (possibly) filesystem notification which is monitoring that file. In contrast, if we create a new file, we will not touch the original one and filesystem listener will not be notified.

xupefei commented 8 years ago

But the solution in this PR still have one problem: It will still ask for UAC if user is opening a file from a read-only device, e.g. CDROM.

mauroservienti commented 8 years ago

In real Windows OS the ACL policy is usually applied on dictionaries, not on single file, so test the write permission on the dictionary is (in most cases) also effective for that file.

Yeah, agree. The fact is that, IMHO, usually and in most cases are not a solution but a workaround. That's it.