Visual Studio 代码终端,如何以管理员权限运行命令? [英] Visual studio code terminal, how to run a command with administrator rights?

查看:487
本文介绍了Visual Studio 代码终端,如何以管理员权限运行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新版本 1.2.0 包含一个终端,但是当我尝试使用 node 安装任何包时,我得到了 npm ERR!代码EPERM,我通常解决右键单击并以管理员身份运行它.那么我如何在 vscode 终端中做到这一点呢?有类似 sudo for linux 的东西吗?

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?

推荐答案

Option 1 - Easier &持久化

以管理员身份运行 Visual Studio Code 应该可以解决问题.

Option 1 - Easier & Persistent

Running Visual Studio Code as Administrator should do the trick.

如果您使用的是 Windows,则可以:

If you're on Windows you can:

  1. 右键单击快捷方式或应用程序/exe
  2. 转到属性
  3. 兼容性标签
  4. 勾选以管理员身份运行此程序"

虽然有一个警告

确保您关闭了所有其他 VS Code 实例,然后尝试以管理员身份运行.Electron 框架喜欢在关闭进程时停止进程,因此最好检查您的任务管理器并终止剩余进程.

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.

如果出于某种奇怪的原因这不是以管理员身份运行您的命令,您可以尝试 runas 命令.微软:runas 命令

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

  • runas/user:Administrator myCommand
  • runas "/user:First Last" "my command"
  • 不要忘记在任何有空格的地方加上双引号.
  • 此外,您很可能从未在管理员帐户上设置密码,因为它会在尝试运行命令时要求您输入密码.如果帐户具有管理员访问权限/权限,则您始终可以使用没有管理员用户名的帐户.

这篇关于Visual Studio 代码终端,如何以管理员权限运行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆