pro*_*365 17
我写了一个小片段,将其添加到脚本的开头。
if(!([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList "-File `"$($MyInvocation.MyCommand.Path)`" `"$($MyInvocation.MyCommand.UnboundArguments)`""
Exit
}
}
Run Code Online (Sandbox Code Playgroud)
这将检查脚本是否具有提升的权限,如果没有,将显示 UAC 对话框(如果启用了安全桌面,则为模式对话框),要求提供管理员凭据以自动提升。
| 归档时间: |
|
| 查看次数: |
8299 次 |
| 最近记录: |