-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Allow to save files that need user elevation #1614
Comments
I've got a debugger extension that needs to be run with privilege. On Linux, |
@sstjohn You can run Code as administrator on Windows, and that should inherit to all child processes. It is just not very good UX at the moment:
|
Oh I get it, I was trying to run multiple instances in the same login session with different privileges. Thanks for the pointer, I'd suggest this could use a little documentation at least. |
This is somewhat related to this question http://stackoverflow.com/questions/31458077/mac-user-running-mamp-issues-trying-to-modify-files-inside-root-folder-eacce?noredirect=1#comment50887510_31458077 An item on uservoice also has been created: http://visualstudio.uservoice.com/forums/293070-visual-studio-code/suggestions/8915236-visual-code-w-terminal-integrated-and-super-admin Seems like there is a need for a os-independant solution to be able to edit files which need administrator password / elevated rights. |
@felixfbecker |
Even if I close all Code Instances, I cannot get an elevated Code on Windows. This makes Code unusable for my use cases. It doesn't matter if I use RunAs or execute code in an elevated cmd or powershell prompt, it is not elevated. |
I think I found something that should help with this: https://www.npmjs.com/package/electron-sudo |
+1 |
Please implement. That the only thing prevents me from deploying as default editor on servers instead of notepad++ which does it out of the box. |
Would love to see VS Code handle this more gracefully! |
Sublime Text does this in a very nice way. It will only pop up an OS prompt asking to type in the password. The editor doesn't even restart (I guess it runs the save in a forked background process) |
I hit this problem every single day, it would be really nice if there was a way to fix this. My main problem is not being able to open new Code instances if already opened and running elevated. Opening a second instance non-elevated when choosing "Open with Code" in File Explorer would solve the main problem, but handling saves similarly to what Notepad++ is doing would be really neat as well. |
I go to the executable directory, goto compatability, switch on "run as administrator". I am prompted to authorize elevated privileges when opening a directory in code (via context menu). However, when running terminal inside elevated Code.exe process, the terminal still is not admin. |
Any updates on this? It could be nice to have a prompt asking for the password like sublime or atom does |
I like vscode - however in atom you open "admin read-only" file as normal user eg. |
Using sudo-prompt you can now retry to save as admin when saving fails. This will work on macOS, Linux and Windows: There are some design decisions that I took that are worth mentioning where behaviour is maybe different from what others do:
I think this covers the scenario where you quickly need to make a change to a file that needs elevation. It is not meant as a way to work on a bunch of files for a longer period and where you have to create files and folders as admin. For that I think VS Code is not suitable. Rather, if you need to do that, use a file manager with admin rights. This will be available in insiders as soon as we have released our 1.19 version this week. |
@bpasero Any particular reason for those design decisions vs the standard behavior? Namely, it automatically prompting if you don't have permission to save a file and allowing you to create/save hidden files, so long as you supply the permissions? It seems like a step back in terms of UX to have those limitations. |
@tenpaiyomi not sure what would define the "standard" behaviour really. E.g. I am not aware of UX guidelines for how to do this in a standard way. The only typical flow I know of is to run the tool as super user / admin (something we do not encourage for VS Code and now you no longer have to in most cases). I chose this way because I think executing an operation as root should be done with great care. I do not think an editor is the right tool for creating file/folder structures as admin user. As to getting repeated prompts and errors for each save, that is maybe something we could revisit later based on feedback. Here I am maybe overly cautious to prevent harm. However to justify my rationale: I find it a bit weird to just popup a login dialog out of nowhere. As a user you could have auto save enabled and that would mean typing and waiting for a short moment would suddenly bring up a (scary) modal dialog for logging in. All in all, I suggest that people give it a try once this hits insider and then we can continue the discussion in here. After all, its just the beginning of the milestone so there is plenty of time to talk about. |
@bpasero When I say standard behavior, I more refer to how things generally tend to work in the scenarios that I have experienced. For example, in Sublime Text, if I am editing a file that requires sudo to save, when I go to save it will automatically prompt me if my current permissions are not adequate. It seems more intuitive to just prompt the user versus saying "Hey, you can't do that, you need to click this button to attempt to save again and then get prompted." |
@bpasero you write:
Can you explain why you think in such way (where is problem)? |
@tenpaiyomi yeah I get that, however there can be many reasons why I file cannot be written to. For example it could be readonly (which is unrelated to permissions), would you then expect that when you save as admin, the readonly flag should go away? And what if the file belongs to another user, would'nt it make more sense to ask to log in as that user instead of logging in as admin? @kamil-kielczewski I think writing files as admin gets messy when it comes to permissions: Should the file/folder only be readable by the admin or any user? Should it be writeable by any user or only the admin? I think creating a file as admin at the minimum has to ask what permissions to use in that case where you are impersonating as admin. If you run the tool as admin, I think you are free to do whatever you want. Btw when I checked ST, you are not able to create a file as admin by saving it to a location that needs admin privileges. So they seem to follow a similar model. |
@bpasero I think the editor should behave exactly as operating system (e.g. linux) - so when I create file (or similar folder) by editor (an need admin permissions) I should get the same result as execute
If this behaviour is not implemented, i need to open terminal, do this by hand, and go back do editor again. When file is readonly situation is similar, I would like to get the same "access level" as using
command. However as I remember, many editors in windows ask USER: "This file is read-only - do you realy want to save changes" and if user agree then they save changes but not change any permissions (read-only flag also not changes). So In read-only case editor can always ask user "do he know what he do" (usually vscode users are programmers so the know what they do :) ) My thinking is right? |
I pushed some changes to allow to save a) readonly files and b) hidden files. For a) you will see an explicit action that explains what is going on: For b) we just truncate the file first before writing and then using I still plan to look into making the experience on Windows a bit better. The prompt that shows up is a bit scary if you look at the details. Ideally we could elevate a child process of VS Code itself to admin rights so that the prompt shows the VSCode icon to the user. |
I really appreciate that you fix this issue. When new VSC update will be available I will test it and give feedback. This fix will be helpful for many developers. Thank you :) |
@kamil-kielczewski it should be available in todays insider release: You can give our preview releases a try from: https://code.visualstudio.com/insiders/ |
Ok @bpasero I install and test you fixes: Main functionality which I want: Minor functionalities like: So to this point I am satisfied (however It will be good to have also minor functionalities; implement nice modal windows for user dialogs will be also nice feature) Tank you :) |
@kamil-kielczewski I suggest to open new issues for new feature requests. I am not sure I understand the issue with not seeing hidden folders and files. I see hidden files in the VS Code explorer. |
hm strange - may be it was my mistake - now I see hidden files. So everything ok :) |
I often need to edit config files (MySQL, PHP, Apache, ...) in directories like C:\Program Files that require administrative rights. When you open them with code and save the file it says "Permission denied". So I have to run Code with right click as administrator and then choose "open file" to open the file. Once, it is not possible to simply drag&drop the file into the elevated Code. The other problem is, once I already have code instance running without elevated rights (say I have my project open and now I need to edit a config) I cannot get another instance with elevated permissions. UAC asks for permissions and a new Code window opens, but it is not elevated, when I save it says permission denied. I have to close my project before I can get an elevated Code instance.
I don't know if that is a restriction of Windows but seeing that you can, for example, run a normal Powershell and an elevated Powershell side-by-side I think this should be possible. The optimal case of course would be if Code could elevate itself if it can't save a file because of insufficient permissions. But being able to run elevated and non-elevated side-by-side would already help a lot.
The text was updated successfully, but these errors were encountered: