一般使用的时候,顶部会显示时候为 管理员。

如何查看当前是否为管理员

  1. #Requires -RunAsAdministrator

输出:

无法运行脚本“ MyScript.ps1”,因为它包含一个“ #requires”语句以管理员身份运行。当前的Windows PowerShell会话未以管理员身份运行。使用“以管理员身份运行”选项启动Windows PowerShell,然后尝试再次运行脚本。

Windows terminal 管理员

以管理员权限打开 PowerShell,运行以下命令:

  1. $basePath = "Registry::HKEY_CLASSES_ROOT\Directory\Background\shell"
  2. New-Item -Path "$basePath\wt" -Force -Value "Windows Terminal here"
  3. New-ItemProperty -Path "$basePath\wt" -Force -Name "Icon" -PropertyType ExpandString -Value "X:\path\to\terminal.ico"
  4. New-Item -Path "$basePath\wt\command" -Force -Type ExpandString -Value '"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe" -p Ubuntu -d "%V"'