microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.95k stars 28.77k forks source link

Allow to open different windows with different permissions #6560

Closed MullenStudio closed 1 year ago

MullenStudio commented 8 years ago

Steps to Reproduce:

  1. Close all Code instances, then run Code as administrator (a new blank Code instance with administrator right)
  2. In File Explorer, right click a text file and Open with Code, nothing will happen.

Note: there are multiple other ways to trigger this issue, the above repro is just an example. Note 2: If you already have a code instance running without administrator running, the above issue will not get triggered. That's why the very first step is to close all Code instances.

bpasero commented 8 years ago

I would say this is impossible today given our process architecture.

StarTether commented 7 years ago

Why is this impossible? Is there a way to make it possible?

rainersigwald commented 7 years ago

Would it be possible to include the elevation status in the pipe name so there are two parallel pipes for elevated and non-elevated processes?

DfernandezNipo commented 7 years ago

Hi. If you try to open a file in VS Code from command line using -r option to reuse existing window still fails if you have opened it using admin rights.

johlju commented 7 years ago

Opening VS Code as elevated administrator in Windows. Then open an elevated PowerShell prompt and movide to a folder, then issue code . will open the folder in VS Code in a new window. But if the PowerShell prompt is not elevated this does not work. I was expecting it to open in a new window, but not elevated.

demali commented 6 years ago

I didn't remember if my last code window was opened as admin and I was unable to open a new window running code . until I read this issue. Is there a way to know that code is running in admin mode? I don't see it on the title bar.

ryansimmen commented 6 years ago

The workaround for this is to force code to always run as administrator by right clicking on the exe, going to Properties, clicking on the Compatibility tab and check the box labeled "Run this program as an administrator".

ghost commented 6 years ago

When there is no vscode process running, if you first open a file/folder as:

The error is coming from:

https://github.com/Microsoft/vscode/blob/397b45b76dba2e9f0520664d1527b3d526fe4ae7/src/vs/code/electron-main/main.ts#L226-L233

In case of EPERM, should it try to launch a new process? The code above this line would need to be changed to support array PIDs.

ghost commented 6 years ago

Maybe we should look at other electron-based apps, how they are handling multiple instances on windows and fix this issue. This is hurting the user experience. I had a demo effect with this one, which silenced the audience who were otherwise applauding the use of VSCode and it's code path/to/file shortcut..

spakh commented 6 years ago

This just happenned to me as well. "A second instance of Code is already running as administrator".

Baffling that this happens. Posting it just to update the date on the thread that the issue is still around. Running on Windows 7 x64 (Powershell 3.0) using Code version 1.21.1

brandonchastain commented 6 years ago

+1 also happening to me. I'm confused by this thread. Is this behavior by-design or incorrect? I figure a text editor should be able to have as many instances as I want.

flupkede commented 6 years ago

+1 also happening to me. Seems to be dependent on OS and UAC settings.

kbrowns commented 6 years ago

I'm curious what the status is on this? There are numerous other reports of this - all of them being closed as a dupe (some with links back to this, others with no links). I see this has been open for 2 years

justin-romano commented 6 years ago

Anyone looking at this?

rtpHarry commented 6 years ago

I have only just started experiencing this problem since a recent update. Not sure if it was the recent windows creators update that has changed things or if it was a release of vscode. I don't specifically run as admin for the first copy, it seems to do it for itself, and then decides not to when I want to open a second file.

For now a sort of workaround, as mentioned above, is that I have set "run as admin" in the .exe properties, but this means I now have to click the yes prompt every time I open vscode.

When it does open, it opens into the same copy of vscode thats running, not a second instance.

ghost commented 6 years ago

Looking at the other highest voted issues being ignored by @bpasero and co., such as https://github.com/Microsoft/vscode/issues/10121, it doesn't seem like they care much. Even the pull requests are sitting there unmerged without any explanation for months/years.. Why would anyone spend time to fix this issue, open a pull-request and get ignored for the rest of my life? This project need serious love and better maintainers.

brownbl1 commented 6 years ago

@kasper3 The workaround, as mentioned above (https://github.com/Microsoft/vscode/issues/6560#issuecomment-353100020) is to force vscode to always open as admin. There are clearly technical issues behind why this and #10121 haven't been implemented yet. It's definitely not true that the maintainers don't care.

earthday commented 6 years ago

Run this program as an administrator works for me.

image

justin-romano commented 6 years ago

This does not help for using the shell menu. That's the really annoying thing. Even if the shell menu elevated the session through UAC

On Tue, Jun 12, 2018 at 2:09 PM, Bright Chen notifications@github.com wrote:

Run this program as an administrator works for me. [image: image] https://user-images.githubusercontent.com/90078/41266204-82ca3368-6e28-11e8-8e88-a2e0d37a4cd8.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode/issues/6560#issuecomment-396442643, or mute the thread https://github.com/notifications/unsubscribe-auth/ABoM2j9K5vRAe0E_oAM0L7hEBhbTzg-Nks5t7yLQgaJpZM4IivsR .

-- Justin Romaine Senior Systems Architect Spark Dental Technology justin.romaine@gmail.com ph 021 764 506 hm 09 445 9166

DfernandezNipo commented 6 years ago

I know that running always as Administrator is a Microsoft tradition to solve some problems, but I want to run it with the minimum permissions that the program needs each time.

justin-romano commented 6 years ago

Why can't it just run another instance unelevated

On Tue, 12 Jun 2018, 6:52 PM Daniel Fernandez Nipo, < notifications@github.com> wrote:

I know that running always as Administrator is a Microsoft tradition to solve some problems, but I want to run it with the minimum permissions that the program needs each time.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode/issues/6560#issuecomment-396484499, or mute the thread https://github.com/notifications/unsubscribe-auth/ABoM2pXiwKLF6c8vPW8c6vTMntgfF8ilks5t72U8gaJpZM4IivsR .

rtpHarry commented 6 years ago

I have implemented this solution but it seems that it prevents me from being able to drag and drop files onto the editor to load them, it just shows the no drop zone cursor when I try.

StarTether commented 6 years ago

I mostly use an elevated process to alter the hosts file when testing. I've found that VS Code will fail to save and then prompt to try again elevated. Approving will cause VS Code to elevate temporarily at which point I can actually save. VS Code will then revert back to lower permissions. I find this is sufficient for my needs, but I do not know such prompts will always happen when there are insufficient privileges. I'm also not sure if there are other situations where I need VS Code to elevate.

kine commented 6 years ago

To add usecase when I need elevated perm inside VSCode> I am using VSCode in elevated mode because working with docker from the console/powershell scripts started from the console, thus needed higher permissions.

simkessy commented 6 years ago

I'm running into this issue. So I can't open a file from explorer if I have another instance open, but I also can't drag and drop the file into the opened instance. This is pretty annoying.

ronaldroe commented 6 years ago

I had this issue. I found the executable for Code, went to properties, Compatibility, and unchecked "Run as Administrator". No issue after that.

justin-romano commented 6 years ago

Here's how i think it should go down. If you have an open elevated code.exe when using the shell integration to open a file it should create a new non-elevated vscode instance. A nice feature would be to have another shell context item to offer open elevated. Its posible but im too busy to do it

On 31/08/2018 6:12 AM, "Ronald Roe" notifications@github.com wrote:

I had this issue. I found the executable for Code, went to properties, Compatibility, and unchecked "Run as Administrator". No issue after that.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode/issues/6560#issuecomment-417415629, or mute the thread https://github.com/notifications/unsubscribe-auth/ABoM2rNvk8Qhg2o1-84NWW3HppcswYirks5uWCsfgaJpZM4IivsR .

DfernandezNipo commented 6 years ago

@ronaldroe the problem is that sometimes you need administrator rights in the integrated terminal window, and I don´t think running always as administratos is a solution. This issue is the cause of still having another light code editor installed in my computer.

giorgio79 commented 6 years ago

Notepad++ nicely opens a new tab. I don't understand why VS Code cannot do the same...

justin-romano commented 6 years ago

It can. Just devs dont think this is a priority. Slipping back into microsoft "to big to care" attitude maybe? ;~)

On Mon, 10 Sep 2018, 6:08 AM György Chityil, notifications@github.com wrote:

Notepad++ nicely opens a new tab. I don't understand why VS Code cannot do the same...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode/issues/6560#issuecomment-419733824, or mute the thread https://github.com/notifications/unsubscribe-auth/ABoM2koWxTBpiqlOlPIzQ4lQE1y8zqN0ks5uZVkLgaJpZM4IivsR .

giorgio79 commented 6 years ago

PS @ronaldroe 's recommendation worked for me meanwhile :)

ailjushkin commented 5 years ago

@ryansimmen Thank you, this works perfect

brunolm commented 5 years ago

Use case where this gets in the way:

I was not signedin Github, to sign in it opens a URL and asks me to click Continue, if I do it tries to open VSCode, if it's already open I can't login

z-aki commented 5 years ago

@ronaldroe how to resolve the same issue on Mac? macOS Mojave 10.14.2 (18C54) visual code studio 1.32.1. I was running it full screen. Put laptop to sleep for sometime, came back and it is empty grey(dark themed). I waited for some time and then force quit it. I couldn't open it still. Also I opened activity monitor, searched for "code" and quit the process "code" and some "code helper"s after which I was able to delete the app which I couldn't do earlier and reinstalled from the zip file but no help. So last resort, restart. After which I could finally open it.

ronaldroe commented 5 years ago

@anktkr Wish I could tell you. I don't have a Mac, and I've never owned one. I hope someone else is able to help you.

ghost commented 5 years ago

+1

truebluebamboo365 commented 4 years ago

Simply don't open using admin but open all projects in command line eg code .

rjmholt commented 4 years ago

I just hit this in the latest insiders, but the issue for me is that I didn't get any warning about it.

I had an admin code window open that I'd forgotten about, went to open a new code session in a project with code ./path/to/project and just got a beep. Had to play around a bit before I tried closing the admin window and found that that worked.

The workaround is easy enough, I'd just love a dialogue just to tell me "you've got an admin code instance running and you need to close it to run code as non-admin".

justin-romano commented 4 years ago

I cannot see why there is an issue with have an elevate and vscode and non-elevated instance open at the same time. If not it suggests a serious floor in the architecture windows\notepad.exe can do this why cant code. after all it is ultimately a native executable module

On Fri, Aug 21, 2020 at 4:11 AM Robert Holt notifications@github.com wrote:

I just hit this in the latest insiders, but the issue for me is that I didn't get any warning about it.

I had an admin code window open that I'd forgotten about, went to open a new code session in a project with code ./path/to/project and just got a beep. Had to play around a bit before I tried closing the admin window and found that that worked.

The workaround is easy enough, I'd just love a dialogue just to tell me "you've got an admin code instance running and you need to close it to run code as non-admin".

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/microsoft/vscode/issues/6560#issuecomment-677759196, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANAZWWH5SV3PWDWUHPSK3DSBVDLDANCNFSM4CEK7MIQ .

-- Justin Romaine Senior Systems Architect Spark Dental Technology justin.romaine@gmail.com ph 021 764 506 hm 09 445 9166

jonfleming commented 3 years ago

Another workaround for when you right-click a file and select Open with VS Code from the context menu:

You can use RegEdit to change the command under Computer\HKEY_CLASSES_ROOT*\shell\VSCode\command from "C:\Path\to\VSCode.exe" "%1" to "C:\Path\to\VSCode.exe" "%1" --user-data-dir=C:\Temp

The --user-data-dir command-line option allows you to open multiple distinct instances of Code.

bpasero commented 3 years ago

As part of our issue grooming effort this month, we might look into support for this issue. The only way how we can support opening different windows of VSCode with different permissions is by creating a different user-data-directory (the place all our config etc. goes) depending on wether you run with elevated permissions or not. The reason is this:

Suggested fix is to detect elevated permissions on startup and depending on that derive a user-data-dir that is different from the normal one.

Pros:

Cons:

Happy for feedback.

deadlydog commented 3 years ago

you cannot share any settings, keybindings etc. between running as admin or not

This would be a deal breaker in my books. I wouldn't expect simply opening an app as admin to lose all of my settings, and any changes that I did make to not be reflected back when running the app not as admin. If you were to go this route, I'm sure this would get reported as a bug pretty quickly.

deadlydog commented 3 years ago

Perhaps instead of allowing both admin and non-admin windows to be open at the same time, a good alternative would be to simply improve the user experience when opening multiple windows to make it easy to run all instances as admin or non-admin.

So if you have an admin instance running and you try and open new non-admin instance, instead of seeing this error: image you would instead get a message saying "A second instance of Code is already running as administrator. All instances must run as admin, or not as admin.", and then have buttons "Open new instance as admin", "Reload other instances as non-admin", "Cancel" (which wouldn't open a new instance).

You might want to also show that dialog when running a non-admin instance and the user chooses to open a new instance as admin. Currently they don't receive an error, but the new instance opens as non-admin.

Basically, just make it easier for people to run multiple instances.

bpasero commented 3 years ago

This would be a deal breaker in my books. I wouldn't expect simply opening an app as admin to lose all of my settings, and any changes that I did make to not be reflected back when running the app not as admin. If you were to go this route, I'm sure this would get reported as a bug pretty quickly.

To be fair, given our settings sync support it would be relatively easy to have both instances share the same settings and extensions by just enabling settings sync.

Letting a admin-instance of VSCode writing to the same user data location as the non-admin one is really dangerous. If you e.g. save settings as admin and then open as non-admin, that non-admin instance will not be able to read or write this settings file. The fact that we did not pick different user data locations based on admin permissions was actually a bad design choice.

Perhaps instead of allowing both admin and non-admin windows to be open at the same time, a good alternative would be to simply improve the user experience when opening multiple windows to make it easy to run all instances as admin or non-admin.

In principle, I like the idea of offering to open as admin from that dialog. I see no way of "reloading other instance as non-admin" because how would the non-admin version be able to talk to the admin version and tell it to do something? That would bypass any security model here. There is literally no way a non-admin launch can do anything within the admin-instance and I think we should keep it that way.

casperease commented 3 years ago

This is delaying our team on a daily basis - please fix soon

casperease commented 3 years ago

Another workaround for when you right-click a file and select Open with VS Code from the context menu:

You can use RegEdit to change the command under Computer\HKEY_CLASSES_ROOT*\shell\VSCode\command from "C:\Path\to\VSCode.exe" "%1" to "C:\Path\to\VSCode.exe" "%1" --user-data-dir=C:\Temp

The --user-data-dir command-line option allows you to open multiple distinct instances of Code.

I did this - still doesnt work. If I have an instance open as admin, i cant open another instance. This problem is a huge stopper for - making us consider using another IDE altogether

pixelbart commented 3 years ago

+1

For me it helped to set the default editor in WinSCP manually and then give admin rights there in the target directory code.exe. So there are no more problems with me. Also not when I edit a temporary file with WinSCP and open a local file in code at the same time.

Maybe this helps someone else.

brunolm commented 3 years ago

If File > New Window works, can't we just have an workaround where code takes a new parameter --new-window and it opens a new window from the last opened instance (or a new instance if none is open) or something?

chAlices commented 3 years ago

I have a instance open as admin. If I tried to open another instance and not as admin, the error would appeared. So @deadlydog is right. You should open all instance as admin, or as non-admin. But I dont know why should I do this???... Why I cant open a instance as admin and another as non-admin?

dpotterNSM commented 3 years ago

as titled, this bug isn't just about Admin/Non-admin. i can be logged into 100 different Windows file explorer instances as 100 different AD network accounts to folders where those 100 different users have permissions to read/write files, one user per folder... Right click on a file in all 100 and select Open in Notepad? all 100 open and save correctly. Right click and try to open any of them in VS Code? new empty/blank tab opens with the right file name and no warning about permissions until you try to save it. none of these are 'admin' users on my box or any other box the files are being served from. this is a horrible user experience as i have no idea why a blank file has apparently opened and i don't expect that file to be blank.

I need to be able to open and save files just like Notepad does, in terms of users permissions being respected from the source I'm opening it from. I don't care about how many windows this uses or if those VS Code instances have to start with default settings because it can't read my user settings. I just want it to fundamentally work the way other text editors do in regards to permissions being respected from the source. You guys are Microsoft and have the source code to Notepad, so you should be able to find out how it does this. all of my Notepad settings are respected (font size, etc.) so they must be coming from my registry, which does not care about file permissions. That would probably be a good place to (optionally) put VS Code user settings going forward if that resolves the overall permissions issues with the least amount of breaking changes.