1

If I open an instance of Visual Studio Code in administrator mode, then I cannot open another instance of Visual Studio Code at all until I close the administrator mode instance. Nor can I open any files in the administrator mode instance using Windows Explorer. Apparently, this is considered useful and by design, although I can't for the life of me see what's useful about it.

However, Visual Studio Code is the Microsoft recommended way to do PowerShell scripting, but PowerShell in the Visual Studio Code terminal won't work unless Visual Studio Code is opened in administrator mode because PowerShell requires administrator mode in order to do anything.

So if I open Visual Studio Code in administrator mode, I can't open any files, or any other Visual Studio Code instances, but if it's not in administrator mode, PowerShell won't work. How is that supposed to work?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Neutrino
  • 8,496
  • 4
  • 57
  • 83
  • How is this not a duplicate? – Peter Mortensen Jun 21 '23 at 13:34
  • What version of Visual Studio Code? It *could* have been broken by an update (there are instances of this). – Peter Mortensen Jun 21 '23 at 14:00
  • Related: *[I have to open Visual Studio Code as administrator or I won't be able to open a terminal](https://stackoverflow.com/questions/72104786/i-have-to-open-visual-studio-code-as-administrator-or-i-wont-be-able-to-open-a)* – Peter Mortensen Jun 21 '23 at 14:04
  • [Visual Studio Code v1.60.0 had a bug](https://stackoverflow.com/questions/69047142/vscode-is-suddenly-defaulting-to-powershell-for-integrated-terminal-and-tasks/69050730#69050730). – Peter Mortensen Jun 21 '23 at 14:08
  • Related: *[Visual Studio Code terminal is failing to launch](https://stackoverflow.com/questions/63202834/visual-studio-vs-code-code-terminal-is-failing-to-launch)* – Peter Mortensen Jun 21 '23 at 14:37
  • Related: *[How to launch Visual Studio Code terminal as a different user](https://stackoverflow.com/questions/52390289/how-to-launch-visual-studio-code-terminal-as-different-user)* – Peter Mortensen Jun 21 '23 at 14:47
  • Related: *[How can I run a command with administrator rights with Visual Studio code terminal?](https://stackoverflow.com/questions/37700536/visual-studio-code-terminal-how-to-run-a-command-with-administrator-rights)*. E.g. *"this error can also occur if files are locked by Windows"* – Peter Mortensen Jun 21 '23 at 16:11
  • Perhaps [the attempt](https://stackoverflow.com/questions/37700536/how-can-i-run-a-command-with-administrator-rights-with-visual-studio-code-termin/76517999#76517999) should be documented. – Peter Mortensen Jun 21 '23 at 16:26
  • None of the posts you've linked are anything to do with the question I'm asking here. You are linking posts about people trying to change the default terminal from cmd.exe to bash, people who can't open the terminal at all, and how to run the terminal in admin mode. None of those is what I'm asking here. – Neutrino Jun 21 '23 at 19:21

1 Answers1

-2

When you open Visual Studio Code in admin mode it is expected that you won't be able to open any additional instances of the editor or open files directly from Windows Explorer because admin mode can restrict certain actions. This is a security measure put in place to prevent unauthorized access to sensitive files and functions on your computer.

As for the PowerShell issue, it is true that PowerShell requires admin privileges to execute certain commands and scripts. One workaround for this is to launch Visual Studio Code normally and then open a PowerShell terminal within the editor that is running as an administrator.

To do this, you can open Visual Studio Code normally and then navigate to the Terminal menu and select "New Terminal". Once the terminal window opens, you can right-click on the tab and select "Run as Administrator". This will launch a PowerShell terminal within Visual Studio Code with the necessary admin privileges.

Alternatively, you can create a shortcut that launches Visual Studio Code with admin privileges by right-clicking on the desktop icon and selecting "Properties". In the Properties window, navigate to the "Shortcut" tab and click on the "Advanced" button. Check the box next to "Run as administrator" and click "OK" to save the changes. This will allow you to launch Visual Studio Code with admin privileges whenever you need to use PowerShell within the editor.

  • In VSCode, you can launch a new terminal window by clicking on the Terminal tab located on the lefthand side of the window. Once the terminal window opens, you can then run commands as an administrator by prefixing the command with "sudo" which will prompt you to enter your administrator password However, if you want to launch a new terminal window as an administrator, you can right-click on the VSCode icon and select Run as Administrator (Windows) or use the sudo command in the terminal. Again, you will need to enter your administrator password in order to run commands as an administrator –  Jun 20 '23 at 21:52
  • There is no Terminal tab on the left side of the window, as far as I can tell. Are you referring to the _views_ selectable via the strip of icons next to the left edge of a VSCode window? Nothing there opens a terminal. Yes, if you know what _shell command_ you can use from _inside_ a given shell to start an elevated (run-as-admin) shell, you can use that (`sudo` only applies to Unix environments), but that is unrelated to the VSCode GUI. – mklement0 Jun 20 '23 at 22:00
  • 4
    This (and your other recent answers) looks like ChatGPT – DavidW Jun 21 '23 at 08:23
  • 1
    On Win10 with latest Vscode right clicking the terminal tab does not have a "Run as Administrator" menu item. – Neutrino Jun 21 '23 at 08:56
  • 2
    The suggestion to run vscode itself as admin using a shortut just recreates the problem I originally stated, which is that once you've done that you can't open any files from Explorer or any other vscode windows. – Neutrino Jun 21 '23 at 08:58
  • 3
    Welcome to Stack Overflow! Most or all of your answers appear likely to have been entirely or partially written by AI (e.g., ChatGPT). Please be aware that [posting of AI-generated content is banned here](//meta.stackoverflow.com/q/421831). If you used an AI tool to assist with any answer, I would encourage you to delete it. Thanks! – NotTheDr01ds Jun 21 '23 at 23:32
  • 2
    **Readers should review this answer carefully and critically, as AI-generated information often contains fundamental errors and misinformation.** If you observe quality issues and/or have reason to believe that this answer was generated by AI, please leave feedback accordingly. The moderation team can use your help to identify quality issues. m – NotTheDr01ds Jun 21 '23 at 23:32