'Visual studio code terminal, how to run a command with administrator rights?
Solution 1:[1]
Step 1: Restart VS Code as an adminstrator
(click the windows key, search for "Visual Studio Code", right click, and you'll see the administrator option)
Step 2: In your VS code powershell terminal run Set-ExecutionPolicy Unrestricted
Solution 2:[2]
In my case even while running as admin I had to set the execution policy.
In the terminal type:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
Solution 3:[3]
Running as admin didn't help me. (also got errors with syscall: rename)
Turns out this error can also occur if files are locked by Windows.
This can occur if :
- You are actually running the project
- You have files open in both Visual Studio and VSCode.
Running as admin doesn't get around windows file locking.
I created a new project in VS2017 and then switched to VSCode to try to add more packages. After stopping the project from running and closing VS2017 it was able to complete without error
Disclaimer: I'm not exactly sure if this means running as admin isn't necessary, but try to avoid it if possible to avoid the possibility of some rogue package doing stuff it isn't meant to.
Solution 4:[4]
Here's what I get.
I'm using Visual Studio Code and its Terminal to execute the 'npm' commands.
Visual Studio Code (not as administrator)
PS g:\labs\myproject> npm install bootstrap@3
Results in scandir and/or permission errors.
Visual Studio Code (as Administrator)
Run this command after I've run something like 'ng serve'
PS g:\labs\myproject> npm install bootstrap@3
Results in scandir and/or permission errors.
Visual Studio Code (as Administrator - closing and opening the IDE)
If I have already executed other commands that would impact node modules I decided to try closing Visual Studio Code first, opening it up as Administrator then running the command:
PS g:\labs\myproject> npm install bootstrap@3
Result I get then is: + [email protected]
added 115 packages and updated 1 package in 24.685s
This is not a permanent solution since I don't want to continue closing down VS Code every time I want to execute an npm command, but it did resolve the issue to a point.
Solution 5:[5]
There are two ways you can solve this problem,
For temporary
You can follow these steps for it,
- Search Vscode after in the windows.
- Then right-click and run the VScode as an administrator.
But you can do this every time when you open the VScode.So I supposed it is not the best way to solve this problem.
Best way
You can follow these steps for it,
- Search Vscode after in the windows.
- Then right-click and click the open file location.
- Then you can click the VScode icon and go to the properties.
- Next you want to go to the compatibility tab.
- At the bottom of the tab, there are selection boxes, in there you can see run this program as an administrator selection box you want to tick it.
- Then you can apply those changes and save it.
You can refer to below page to do more things related to this run as administrator stuffs
https://www.sevenforums.com/tutorials/11841-run-administrator.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | cham |
| Solution 2 | Darryl Windsor |
| Solution 3 | Simon_Weaver |
| Solution 4 | Jacques |
| Solution 5 | Dilshan Madhuranga |
