Visual studio code terminal, how to run a command with administrator rights?

Issue

The new version 1.2.0 include a terminal, but when I try to install any pack with node I get the npm ERR! code EPERM that I usually solve right clicking and running it as administrator. So how I do that in the vscode terminal? There is something like sudo for linux?

vscode terminal

Solution

Option 1 – Easier & Persistent

Running Visual Studio Code as Administrator should do the trick.

If you’re on Windows you can:

  1. Right click the shortcut or app/exe
  2. Go to properties
  3. Compatibility tab
  4. Check “Run this program as an administrator”

There is a caveat to it though

Make sure you have all other instances of VS Code closed and then try to run as Administrator. The electron framework likes to stall processes when closing them so it’s best to check your task manager and kill the remaining processes.

Related Changes in Codebase

Option 2 – More like Sudo

If for some weird reason this is not running your commands as an Administrator you can try the runas command. Microsoft: runas command

Examples

  • runas /user:Administrator myCommand
  • runas "/user:First Last" "my command"

Notes

  • Just don’t forget to put double quotes around anything that has a space in it.
  • Also it’s quite possible that you have never set the password on the Administrator account, as it will ask you for the password when trying to run the command. You can always use an account without the username of Administrator if it has administrator access rights/permissions.

Answered By – CTS_AE

Answer Checked By – Gilberto Lyons (AngularFixing Admin)

Leave a Reply

Your email address will not be published.