Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mdavis199/acc52b633a7f1c082e4c3f44e3d6b7d2 to your computer and use it in GitHub Desktop.

Select an option

Save mdavis199/acc52b633a7f1c082e4c3f44e3d6b7d2 to your computer and use it in GitHub Desktop.

Revisions

  1. @SCP002 SCP002 revised this gist May 8, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fix-powershell-context-menu.reg
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ Windows Registry Editor Version 5.00


    ; WARNING:
    ; Uses Visual Studio Code as a standatd editor.
    ; Uses Visual Studio Code as a standard editor.
    ; You might change it to your own with default file path, like:
    ;
    ; [HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Edit\Command]
  2. @SCP002 SCP002 revised this gist May 1, 2021. 1 changed file with 44 additions and 2 deletions.
    46 changes: 44 additions & 2 deletions fix-powershell-context-menu.reg
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,22 @@
    Windows Registry Editor Version 5.00


    ; WARNING:
    ; Uses Visual Studio Code as a standatd editor.
    ; You might change it to your own with default file path, like:
    ;
    ; [HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Edit\Command]
    ; @="\"C:\\Windows\\System32\\notepad.exe\" \"%1\""
    ;
    ; Or using path variables (%SystemRoot% etc.) for portability sake by
    ; creating REG_EXPAND_SZ default value:
    ; @=hex(2):...
    ; with binary representation of a value like:
    ; "%SystemRoot%\System32\notepad.exe" "%1"

    ; Tested with Windows 10 Pro 20H2, build 19042.928


    ; ========================================================= SCRIPTS =========================================================

    ; Associate .ps1 files with powershell scripts
    @@ -43,16 +59,42 @@ Windows Registry Editor Version 5.00
    ; Set 'Open' action to run script
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open]

    ; REG_EXPAND_SZ value of: "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser -Force; & \"%1\""
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command]
    @="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" \"-Command\" \"Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser -Force; & '%1'\""
    @=hex(2):22,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
    00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,\
    69,00,6e,00,64,00,6f,00,77,00,73,00,50,00,6f,00,77,00,65,00,72,00,53,00,68,\
    00,65,00,6c,00,6c,00,5c,00,76,00,31,00,2e,00,30,00,5c,00,70,00,6f,00,77,00,\
    65,00,72,00,73,00,68,00,65,00,6c,00,6c,00,2e,00,65,00,78,00,65,00,22,00,20,\
    00,22,00,2d,00,43,00,6f,00,6d,00,6d,00,61,00,6e,00,64,00,22,00,20,00,22,00,\
    53,00,65,00,74,00,2d,00,45,00,78,00,65,00,63,00,75,00,74,00,69,00,6f,00,6e,\
    00,50,00,6f,00,6c,00,69,00,63,00,79,00,20,00,2d,00,45,00,78,00,65,00,63,00,\
    75,00,74,00,69,00,6f,00,6e,00,50,00,6f,00,6c,00,69,00,63,00,79,00,20,00,42,\
    00,79,00,70,00,61,00,73,00,73,00,20,00,2d,00,53,00,63,00,6f,00,70,00,65,00,\
    20,00,43,00,75,00,72,00,72,00,65,00,6e,00,74,00,55,00,73,00,65,00,72,00,20,\
    00,2d,00,46,00,6f,00,72,00,63,00,65,00,3b,00,20,00,26,00,20,00,5c,00,22,00,\
    25,00,31,00,5c,00,22,00,22,00,00,00


    ; Add 'Run as administrator'
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\RunAs]
    "HasLUAShield"=""

    ; REG_EXPAND_SZ value of: "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser -Force; & \"%1\""
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\RunAs\Command]
    @="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" \"-Command\" \"Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser -Force; & '%1'\""
    @=hex(2):22,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
    00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,\
    69,00,6e,00,64,00,6f,00,77,00,73,00,50,00,6f,00,77,00,65,00,72,00,53,00,68,\
    00,65,00,6c,00,6c,00,5c,00,76,00,31,00,2e,00,30,00,5c,00,70,00,6f,00,77,00,\
    65,00,72,00,73,00,68,00,65,00,6c,00,6c,00,2e,00,65,00,78,00,65,00,22,00,20,\
    00,22,00,2d,00,43,00,6f,00,6d,00,6d,00,61,00,6e,00,64,00,22,00,20,00,22,00,\
    53,00,65,00,74,00,2d,00,45,00,78,00,65,00,63,00,75,00,74,00,69,00,6f,00,6e,\
    00,50,00,6f,00,6c,00,69,00,63,00,79,00,20,00,2d,00,45,00,78,00,65,00,63,00,\
    75,00,74,00,69,00,6f,00,6e,00,50,00,6f,00,6c,00,69,00,63,00,79,00,20,00,42,\
    00,79,00,70,00,61,00,73,00,73,00,20,00,2d,00,53,00,63,00,6f,00,70,00,65,00,\
    20,00,43,00,75,00,72,00,72,00,65,00,6e,00,74,00,55,00,73,00,65,00,72,00,20,\
    00,2d,00,46,00,6f,00,72,00,63,00,65,00,3b,00,20,00,26,00,20,00,5c,00,22,00,\
    25,00,31,00,5c,00,22,00,22,00,00,00



  3. @SCP002 SCP002 revised this gist Apr 4, 2021. No changes.
  4. @SCP002 SCP002 created this gist Apr 4, 2021.
    115 changes: 115 additions & 0 deletions fix-powershell-context-menu.reg
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,115 @@
    Windows Registry Editor Version 5.00


    ; ========================================================= SCRIPTS =========================================================

    ; Associate .ps1 files with powershell scripts
    ; --------------------------------------------------------------------
    ; Set default value to 'Microsoft.PowerShellScript.1'
    [HKEY_CLASSES_ROOT\.ps1]
    @="Microsoft.PowerShellScript.1"


    ; Fix open .ps1 files with any program except 'powershell.exe' or 'powershell_ise.exe' cause content menu settings breakage
    ; --------------------------------------------------------------------
    ; Remove 'OpenWithProgids'
    [-HKEY_CLASSES_ROOT\.ps1\OpenWithProgids]


    ; Change powershell scripts context menu behavior: Add, remove and change default items
    ; --------------------------------------------------------------------
    ; Set default action to 'Open'
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell]
    @="Open"


    ; Remove 'Run with PowerShell'
    [-HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\0]


    ; Set 'Edit' action to open script with VSCode
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Edit]
    "NoSmartScreen"=""

    ; REG_EXPAND_SZ value of: "%LocalAppData%\Programs\Microsoft VS Code\Code.exe" "%1"
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Edit\Command]
    @=hex(2):22,00,25,00,4c,00,6f,00,63,00,61,00,6c,00,41,00,70,00,70,00,44,00,61,\
    00,74,00,61,00,25,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,73,00,\
    5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,56,00,53,\
    00,20,00,43,00,6f,00,64,00,65,00,5c,00,43,00,6f,00,64,00,65,00,2e,00,65,00,\
    78,00,65,00,22,00,20,00,22,00,25,00,31,00,22,00,00,00


    ; Set 'Open' action to run script
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open]

    [HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command]
    @="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" \"-Command\" \"Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser -Force; & '%1'\""


    ; Add 'Run as administrator'
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\RunAs]
    "HasLUAShield"=""

    [HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\RunAs\Command]
    @="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" \"-Command\" \"Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser -Force; & '%1'\""



    ; ========================================================= MODULES =========================================================

    ; Associate .psm1 files with powershell modules
    ; --------------------------------------------------------------------
    ; Set default value to 'Microsoft.PowerShellModule.1'
    [HKEY_CLASSES_ROOT\.psm1]
    @="Microsoft.PowerShellModule.1"


    ; Fix open .psm1 files with any program except 'powershell.exe' or 'powershell_ise.exe' cause content menu settings breakage
    ; --------------------------------------------------------------------
    ; Remove 'OpenWithProgids'
    [-HKEY_CLASSES_ROOT\.psm1\OpenWithProgids]


    ; Change powershell modules context menu behavior: Add, remove and change default items
    ; --------------------------------------------------------------------
    ; Set default action to 'Open'
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellModule.1\Shell]
    @="Open"


    ; Remove 'Run with PowerShell'
    [-HKEY_CLASSES_ROOT\Microsoft.PowerShellModule.1\Shell\0]


    ; Set 'Edit' action to open module with VSCode
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellModule.1\Shell\Edit]
    "NoSmartScreen"=""

    ; REG_EXPAND_SZ value of: "%LocalAppData%\Programs\Microsoft VS Code\Code.exe" "%1"
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellModule.1\Shell\Edit\Command]
    @=hex(2):22,00,25,00,4c,00,6f,00,63,00,61,00,6c,00,41,00,70,00,70,00,44,00,61,\
    00,74,00,61,00,25,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,73,00,\
    5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,56,00,53,\
    00,20,00,43,00,6f,00,64,00,65,00,5c,00,43,00,6f,00,64,00,65,00,2e,00,65,00,\
    78,00,65,00,22,00,20,00,22,00,25,00,31,00,22,00,00,00


    ; Set 'Open' action to open module with VSCode
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellModule.1\Shell\Open]
    "NoSmartScreen"=""

    ; REG_EXPAND_SZ value of: "%LocalAppData%\Programs\Microsoft VS Code\Code.exe" "%1"
    [HKEY_CLASSES_ROOT\Microsoft.PowerShellModule.1\Shell\Open\Command]
    @=hex(2):22,00,25,00,4c,00,6f,00,63,00,61,00,6c,00,41,00,70,00,70,00,44,00,61,\
    00,74,00,61,00,25,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,73,00,\
    5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,56,00,53,\
    00,20,00,43,00,6f,00,64,00,65,00,5c,00,43,00,6f,00,64,00,65,00,2e,00,65,00,\
    78,00,65,00,22,00,20,00,22,00,25,00,31,00,22,00,00,00


    ; Remove 'Run as administrator'
    [-HKEY_CLASSES_ROOT\Microsoft.PowerShellModule.1\Shell\RunAs]