【发布时间】:2021-05-27 10:49:21
【问题描述】:
我正在尝试使用快捷方式以管理员身份运行 PowerShell 脚本。试了很多方法,还是不行:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoExit -Verb RunAs Start-Process powershell.exe -ArgumentList '-file C:\project\test.ps1'
使用此命令,它将创建两个 PowerShell 窗口并关闭一个窗口。
我也试过这个:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoExit Start-Process powershell.exe -Verb RunAs -File 'C:\project\test.ps1'
有人可以帮忙吗?
【问题讨论】:
-
我也试过这个 "powershell.exe -ExecutionPolicy Bypass -NoExit -File "C:\project\test.ps1" " 我可以正常运行但不能以管理员身份运行,因为当我运行管理员,它将转到我的 Powershell 的路径而不是项目的路径。
-
如果你只是想以管理员身份启动 powershell,它会是这样的
powershell.exe -WindowStyle Hidden -command "& {start-process powershell -verb runas}" -
@AaronLi 你能提供任何反馈吗?我的解决方案不适合您吗,您找到其他解决方案了吗,您的问题还存在吗?
标签: powershell working-directory elevated-privileges