用 Start-Process -Verb RunAs 以管理员权限运行命令
从非管理员 PowerShell 会话触发 UAC 提权并启动管理员级别的新进程。
运行 Start-Process powershell -Verb RunAs -ArgumentList '-Command', '<命令>' 即可在提权窗口中执行命令。
01命令
命令
$ Start-Process powershell -Verb RunAs -ArgumentList '-Command', 'Get-EventLog System -Newest 5'02作用说明
非管理员的 PowerShell 不能像 sudo 那样直接切到另一条命令——Start-Process -Verb RunAs 是内置的提权方式,它会在 UAC 弹窗确认后启动一个新进程。提权进程在独立窗口运行,输出不会返回给调用方,需要用 -RedirectStandardOutput 捕获或让子进程写文件。-Wait 会让脚本阻塞到提权进程退出,后续命令依赖其结果时必须加。
03风险
!注意: 通过 -ArgumentList 传入的内容会以管理员权限运行,且不带当前会话的变量上下文——不要把不可信输入拼进命令字符串。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- Start-Process - SS64依据: Shows -Verb RunAs examples and notes that output of the elevated process is not captured.
- Start-Process依据: Documents the -Verb RunAs parameter for UAC elevation.
最后验证: 2026-09-17 · 分类: 系统与设置