Vscode: Allow to open different windows with different permissions

Created on 20 May 2016  Â·  44Comments  Â·  Source: microsoft/vscode

  • VSCode Version: 1.1.1
  • OS Version: Windows 10 1511 (10586.318)

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.

feature-request under-discussion workbench-run-as-admin

Most helpful comment

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".

All 44 comments

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

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

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?

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.

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.

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.

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".

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

  • non-admin, then open as admin, then non-admin again.. it works
  • admin, then open as non-admin, it chokes with the error

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.

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..

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

+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.

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

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

Anyone looking at this?

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.

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.

@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.

Run this program as an administrator works for me.

image

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.[email protected]
ph 021 764 506
hm 09 445 9166

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.

Why can't it just run another instance unelevated

On Tue, 12 Jun 2018, 6:52 PM Daniel Fernandez Nipo, <
[email protected]> 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
.

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.

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.

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.

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.

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

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
.

@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.

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

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
.

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

@ryansimmen Thank you, this works perfect

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

@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.

@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.

+1

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

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".

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.[email protected]
ph 021 764 506
hm 09 445 9166

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.

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:

  • you start VSCode as admin
  • this will open a named pipe for communication with admin privileges
  • you start VSCode as normal user
  • VSCode will try to connect to the named pipe that runs as admin
  • VSCode cannot communicate with that pipe due to insufficient permissions
  • you see that warning dialog that another instance of VSCode is already running as admin

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:

  • this issue is resolved
  • the danger of writing to the user data dir with elevated rights and then running VSCode with normal permissions is prevented (https://github.com/microsoft/vscode/issues/109370)

Cons:

  • you cannot share any settings, keybindings etc. between running as admin or not
  • slight startup perf penalty because in order to find out on Windows if you run as admin, we run some C code (https://github.com/arkon/native-is-elevated/blob/master/src/iselevated.cc)

Happy for feedback.

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.

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VitorLuizC picture VitorLuizC  Â·  3Comments

trstringer picture trstringer  Â·  3Comments

DovydasNavickas picture DovydasNavickas  Â·  3Comments

biij5698 picture biij5698  Â·  3Comments

shanalikhan picture shanalikhan  Â·  3Comments