在PowerShell中以管理员身份运行CMD

时间:2018-11-11 12:55:04

标签: powershell cmd administrator

我正在尝试使用Powershell以管理员身份执行命令提示符。 (例如,当您右键单击cmd图标并选择以管理员身份运行时)。 为此,我应该添加以下内容吗?

& cmd.exe /c $VAR

2 个答案:

答案 0 :(得分:3)

有些晦涩难懂,必须在参数-Verb RunAs中使用Start-Process才能在PowerShell中启动提升的进程(具有管理特权的进程):

# The command to pass to cmd.exe /c
$var = 'echo hello world & pause'

# Start the process asynchronously, in a new window,
# as the current user with elevation (administrative rights).
# Note the need to pass the arguments to cmd.exe as an *array*.
Start-Process -Verb RunAs cmd.exe -Args '/c', $var

答案 1 :(得分:0)

键入以下命令:

runas /noprofile /user:Administrator cmd 

然后输入管理员密码。

相关问题