您可以使用下面的代码创建一个PowerShell脚本来以管理员身份运行映射网络代码:
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powe
该文章提供了一段PowerShell代码示例,用于检查当前用户是否具有管理员角色。如果用户不具备管理员权限,脚本将启动一个新的进程以管理员身份运行,从而能执行映射网络驱动器等需要管理员权限的操作。
2万+

被折叠的 条评论
为什么被折叠?



