Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.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脚本请求管理员权限_Powershell - Fatal编程技术网

如何使用powershell脚本请求管理员权限

如何使用powershell脚本请求管理员权限,powershell,Powershell,如何执行powershell脚本以请求用户的管理员权限?打开modal并接受或输入管理员密码。可能吗 您应该检查您是否不是管理员,并使用相同的参数运行新流程,但使用RunAs意味着RequireEvation标志。请注意,如果UAC被降低或禁用,这可能根本不起作用 启动进程powershell–动词runAs,您可以传递其他属性,如$PSCommandPath 注: 无法升级当前进程 即使在变量中存储了管理员凭据,也不能使用powershell only运行进程提升。 我已经写了一个小片段,将它

如何执行powershell脚本以请求用户的管理员权限?打开modal并接受或输入管理员密码。可能吗

您应该检查您是否不是管理员,并使用相同的参数运行新流程,但使用RunAs意味着RequireEvation标志。请注意,如果UAC被降低或禁用,这可能根本不起作用

启动进程powershell–动词runAs,您可以传递其他属性,如$PSCommandPath

注:

无法升级当前进程 即使在变量中存储了管理员凭据,也不能使用powershell only运行进程提升。
我已经写了一个小片段,将它添加到脚本的开头

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
}
}
这将检查脚本是否具有提升的权限,如果没有,将显示UAC对话框(如果启用了安全桌面),然后使用模态对话框请求管理员凭据自动提升