How can I run a command with administrator rights with Visual Studio code terminal?

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 application (EXE file)
  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 Visual Studio 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 the 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.

Leave a Comment