Advertisement
FreeBooter

Add_Open_PowerShell_window_here_as_administrator_context_menu

Aug 20th, 2022
1,359
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.06 KB | Fixit | 1 0
  1. ::  Add "Open PowerShell window here as administrator" context menu in Windows 10 and Windows 11
  2.  
  3. @Echo Off & Cls
  4.  
  5.  
  6. (Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B)
  7.  
  8. :choice
  9.  
  10. Cls & Mode CON  LINES=11 COLS=95 & Color 0E & Title Created By FreeBooter
  11. Echo.
  12. Echo.
  13. Echo.
  14. Echo        Add "Open PowerShell window here as administrator" to Context Menu       (A)  
  15. Echo.      
  16. Echo        Remove "Open PowerShell window here as administrator" from Context Menu  (R)
  17. Echo.
  18.  
  19.  
  20. Set /p input=^>
  21.  
  22. If /i  Not %input%==A (Goto :_Ex) Else (Goto :_Add)
  23.  
  24. :_Ex
  25. If /i Not %input%==R  (Goto :choice) Else (Goto :_Remove)
  26.  
  27.  
  28.  
  29. :_Add
  30.  
  31. Reg.exe add "HKCR\Directory\Background\shell\PowerShellAsAdmin" /ve /t REG_SZ /d "Open PowerShell window here as administrator" /f
  32. Reg.exe delete "HKCR\Directory\Background\shell\PowerShellAsAdmin" /v "Extended" /f
  33. Reg.exe add "HKCR\Directory\Background\shell\PowerShellAsAdmin" /v "HasLUAShield" /t REG_SZ /d "" /f
  34. Reg.exe add "HKCR\Directory\Background\shell\PowerShellAsAdmin" /v "Icon" /t REG_SZ /d "powershell.exe" /f
  35. Reg.exe add "HKCR\Directory\Background\shell\PowerShellAsAdmin\command" /ve /t REG_SZ /d "PowerShell -Command \"Start-Process cmd -ArgumentList '/s,/k,pushd %%V && start PowerShell -NoExit && exit' -Verb RunAs\"" /f
  36. Reg.exe add "HKCR\Directory\shell\PowerShellAsAdmin" /ve /t REG_SZ /d "Open PowerShell window here as administrator" /f
  37. Reg.exe delete "HKCR\Directory\shell\PowerShellAsAdmin" /v "Extended" /f
  38. Reg.exe add "HKCR\Directory\shell\PowerShellAsAdmin" /v "HasLUAShield" /t REG_SZ /d "" /f
  39. Reg.exe add "HKCR\Directory\shell\PowerShellAsAdmin" /v "Icon" /t REG_SZ /d "powershell.exe" /f
  40. Reg.exe add "HKCR\Directory\shell\PowerShellAsAdmin\command" /ve /t REG_SZ /d "PowerShell -Command \"Start-Process cmd -ArgumentList '/s,/k,pushd %%V && start PowerShell -NoExit && exit' -Verb RunAs\"" /f
  41. Reg.exe add "HKCR\Drive\shell\PowerShellAsAdmin" /ve /t REG_SZ /d "Open PowerShell window here as administrator" /f
  42. Reg.exe delete "HKCR\Drive\shell\PowerShellAsAdmin" /v "Extended" /f
  43. Reg.exe add "HKCR\Drive\shell\PowerShellAsAdmin" /v "HasLUAShield" /t REG_SZ /d "" /f
  44. Reg.exe add "HKCR\Drive\shell\PowerShellAsAdmin" /v "Icon" /t REG_SZ /d "powershell.exe" /f
  45. Reg.exe add "HKCR\Drive\shell\PowerShellAsAdmin\command" /ve /t REG_SZ /d "PowerShell -Command \"Start-Process cmd -ArgumentList '/s,/k,pushd %%V && start PowerShell -NoExit && exit' -Verb RunAs\"" /f
  46. Reg.exe delete "HKCR\LibraryFolder\Background\shell\PowerShellAsAdmin" /f
  47. REM ; To allow mapped drives to be available in elevated PowerShell
  48. Reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v "EnableLinkedConnections" /t REG_DWORD /d "1" /f
  49.  
  50.  
  51.  
  52. Goto :RestartEx
  53.  
  54.  
  55.  
  56. :_Remove
  57.  
  58. Reg.exe delete "HKCR\Directory\Background\shell\PowerShellAsAdmin" /f
  59. Reg.exe delete "HKCR\Directory\shell\PowerShellAsAdmin" /f
  60. Reg.exe delete "HKCR\Drive\shell\PowerShellAsAdmin" /f
  61. Reg.exe delete "HKCR\LibraryFolder\Background\shell\PowerShellAsAdmin" /f
  62.  
  63.  
  64.  
  65. :RestartEx
  66.  
  67. Taskkill /im Explorer.exe /f >Nul
  68.  
  69. Start Explorer.exe
  70.  
  71. Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement