即使以管理员身份运行 PowerShell 也无法更新 wsl

即使以管理员身份运行 PowerShell 也无法更新 wsl

我正在尝试更新我的默认 WSL 发行版,即使我以管理员身份运行 PowerShell,我也收到此错误。我做错了什么?

在此处输入图片描述

答案1

看起来您没有该端点的完整管理员凭据。我自己看到这是由禁用的 UAC 窗口引起的(然后以管理员身份运行终端,而无法真正以管理员身份运行命令),但这可能由多种原因引起。

我建议使用以下链接来绕过或修复该问题:您可以看到一种绕过该问题的方法以及一个有用的脚本来检查您是否实际以管理权限运行:

([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")

来源:https://stackoverflow.com/questions/28990822/running-as-ps-as-admin-but-receive-error-that-operation-requires-elevation

或者仅从 powershell 运行管理 powershell 窗口:

 # Get the ID and security principal of the current user account
 $myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
 $myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
  
 # Get the security principal for the Administrator role
 $adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
  
 # Check to see if we are currently running "as Administrator"
 if ($myWindowsPrincipal.IsInRole($adminRole))
    {
    # We are running "as Administrator" - so change the title and background color to indicate this
    $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
    $Host.UI.RawUI.BackgroundColor = "DarkBlue"
    clear-host
    }
 else
    {
    # We are not running "as Administrator" - so relaunch as administrator
    
    # Create a new process object that starts PowerShell
    $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
    
    # Specify the current script path and name as a parameter
    $newProcess.Arguments = $myInvocation.MyCommand.Definition;
    
    # Indicate that the process should be elevated
    $newProcess.Verb = "runas";
    
    # Start the new process
    [System.Diagnostics.Process]::Start($newProcess);
    
    # Exit from the current, unelevated, process
    exit
    }
  
 wsl --update

来源:https://learn.microsoft.com/en-us/archive/blogs/virtual_pc_guy/a-self-elevating-powershell-script

相关内容