Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

為 .ps1 PowerShell 腳本新增「以系統管理員身分執行」右鍵選單

編輯:Win10 系統基礎知識

PowerShell 腳本 (.ps1) 常需管理員權限修復系統問題(如 Win10 應用程式異常)。為右鍵選單加入「以系統管理員身分執行」,免去先開 PowerShell 再拖曳腳本的麻煩。

登錄表操作步驟

  1. regedit → HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\shell。
  2. 新建鍵值 runas。
  3. 其下新建字串值 HasLUAShield(值留空),顯示 UAC 盾牌圖示。
  4. 在 runas 下新建鍵值 command。
  5. 修改 command 預設值為:
    powershell.exe "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'"

效果

右鍵任意 .ps1 檔案即見「以系統管理員身分執行」,點選自動提權執行。恢復預設只需刪除 runas 鍵值。文末提供 .reg 檔下載雙擊即用。

Copyright © Windows教程網 All Rights Reserved