Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PowerShell中以管理员身份运行CMD_Powershell_Cmd_Administrator - Fatal编程技术网

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

在PowerShell中以管理员身份运行CMD,powershell,cmd,administrator,Powershell,Cmd,Administrator,我正在尝试使用powershell以管理员身份执行命令提示符。(就像您右键单击cmd图标并选择以管理员身份运行时一样)。 为了做到这一点,我应该在以下内容中添加什么 & cmd.exe /c $VAR 键入以下命令: runas /noprofile /user:Administrator cmd 然后输入管理员密码。有些模糊,为了在PowerShell中启动提升的进程(具有管理权限的进程),必须与参数-动词RunAs一起使用: # The command to pass to c

我正在尝试使用powershell以管理员身份执行命令提示符。(就像您右键单击cmd图标并选择以管理员身份运行时一样)。 为了做到这一点,我应该在以下内容中添加什么

& cmd.exe /c $VAR
键入以下命令:

runas /noprofile /user:Administrator cmd 

然后输入管理员密码。

有些模糊,为了在PowerShell中启动提升的进程(具有管理权限的进程),必须与参数
-动词RunAs一起使用:

# 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

这仅适用于内置的
administrator
帐户,该帐户通常出于安全原因被禁用。否则,
runas.exe
不支持从其他帐户的非提升进程按需提升。例如,如果您自己的帐户原则上具有管理权限,但您当前的shell没有提升,
runas
无法在您使用提升时启动另一个进程。但此方法要求我输入密码,因此我无法在jenkins等自动化系统中使用它。或者有没有办法将密码作为参数或类似的东西传递?有没有办法在没有窗口提示询问是或否的情况下传递密码。我的意思是我想为VS cmd打开x64本机工具,但如果我使用启动进程-动词RunAs“C:\Program Files(x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat”一个windows弹出窗口询问是或否,因为我需要在jenkins管道中使用它,它需要自动化,是否有任何参数或解决方法可以做到这一点?@JesusFernandez,此确认对话框是一个重要的安全功能(UAC)。虽然可以停用它,但这样做会带来严重的安全风险。您真的需要以管理员身份运行控制台吗?如果是这样,也许Jenkins本身可以配置为启动提升的进程,那么您就不需要
启动进程-动词RunAs