Opening up Windows Terminal with elevated privileges, from within Windows Terminal

前端 未结 5 699
旧时难觅i
旧时难觅i 2021-01-05 09:30

There are plenty of questions here which asks how to elevate priviliges from powershell, and almost all of them recommend this command:

Start-Process -Verb Ru         


        
5条回答
  •  有刺的猬
    2021-01-05 10:15

    You can create a shortcut to always run Windows Terminal as administrator using this powershell script:

    $WshShell = New-Object -comObject WScript.Shell
    $Shortcut = $WshShell.CreateShortcut("$Home\Desktop\Windows Terminal.lnk")
    $Shortcut.TargetPath = "$env:LOCALAPPDATA\Microsoft\WindowsApps\Microsoft.WindowsTerminal_8wekyb3d8bbwe\wt.exe"
    $Shortcut.Save()
    
    $bytes = [System.IO.File]::ReadAllBytes("$Home\Desktop\Windows Terminal.lnk")
    $bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON 
    [System.IO.File]::WriteAllBytes("$Home\Desktop\Windows Terminal.lnk", $bytes)
    

    You can just paste it and run it from Windows Powershell ISE, it will create a Windows Terminal.lnk file on your desktop. Whenever you double click on that shortcut Windows terminal will run as an admnnistrator

提交回复
热议问题