Skip to content

Instantly share code, notes, and snippets.

@SCP002
Last active October 19, 2024 08:53
Show Gist options
  • Save SCP002/a1700041a969b4eb6af58248c6853222 to your computer and use it in GitHub Desktop.
Save SCP002/a1700041a969b4eb6af58248c6853222 to your computer and use it in GitHub Desktop.
Windows Registry: Run .ps1 scripts with double click using pwsh (PowerShell 7). Including tweaks of context menu. See coments for description.
Windows Registry Editor Version 5.00
; WARNING:
; Uses "%ProgramFiles%\PowerShell\7\pwsh.exe" as powershell path.
; You might want to change it to your own with default file path, like:
;
; @="\"C:\\ProgramFiles\\Powershell\\8\\pwsh.exe\" \"%1\""
;
; Or using path variables (%ProgramFiles% etc.) for portability sake by
; creating REG_EXPAND_SZ default value:
; @=hex(2):...
; with binary representation of a value like:
; "%ProgramFiles%\PowerShell\8\pwsh.exe" "%1"
; Uses Visual Studio Code as a standard editor.
; You might want to change it to your own with default file path, like:
;
; @="\"C:\\Windows\\System32\\notepad.exe\" \"%1\""
; Tested with Windows 11 Pro 23H2 22631.3958
; Set default action for .ps1 scripts to open with pwsh.
; --------------------------------------------------------------------
[-HKEY_CLASSES_ROOT\.ps1]
[HKEY_CLASSES_ROOT\.ps1]
@="ps1_auto_file"
[-HKEY_CLASSES_ROOT\ps1_auto_file]
[HKEY_CLASSES_ROOT\ps1_auto_file]
[HKEY_CLASSES_ROOT\ps1_auto_file\shell]
[HKEY_CLASSES_ROOT\ps1_auto_file\shell\open]
; REG_EXPAND_SZ value of: "%ProgramFiles%\PowerShell\7\pwsh.exe" "%1"
[HKEY_CLASSES_ROOT\ps1_auto_file\shell\open\command]
@=hex(2):22,00,25,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,46,00,69,00,\
6c,00,65,00,73,00,25,00,5c,00,50,00,6f,00,77,00,65,00,72,00,53,00,68,00,65,\
00,6c,00,6c,00,5c,00,37,00,5c,00,70,00,77,00,73,00,68,00,2e,00,65,00,78,00,\
65,00,22,00,20,00,22,00,25,00,31,00,22,00,00,00
[HKEY_CLASSES_ROOT\ps1_auto_file\shell\runas]
"HasLUAShield"=""
; REG_EXPAND_SZ value of: "%ProgramFiles%\PowerShell\7\pwsh.exe" "%1"
[HKEY_CLASSES_ROOT\ps1_auto_file\shell\runas\command]
@=hex(2):22,00,25,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,46,00,69,00,\
6c,00,65,00,73,00,25,00,5c,00,50,00,6f,00,77,00,65,00,72,00,53,00,68,00,65,\
00,6c,00,6c,00,5c,00,37,00,5c,00,70,00,77,00,73,00,68,00,2e,00,65,00,78,00,\
65,00,22,00,20,00,22,00,25,00,31,00,22,00,00,00
[-HKEY_CURRENT_USER\Software\Classes\ps1_auto_file]
[HKEY_CURRENT_USER\Software\Classes\ps1_auto_file]
[HKEY_CURRENT_USER\Software\Classes\ps1_auto_file\shell]
[HKEY_CURRENT_USER\Software\Classes\ps1_auto_file\shell\open]
; REG_EXPAND_SZ value of: "%ProgramFiles%\PowerShell\7\pwsh.exe" "%1"
[HKEY_CURRENT_USER\Software\Classes\ps1_auto_file\shell\open\command]
@=hex(2):22,00,25,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,46,00,69,00,\
6c,00,65,00,73,00,25,00,5c,00,50,00,6f,00,77,00,65,00,72,00,53,00,68,00,65,\
00,6c,00,6c,00,5c,00,37,00,5c,00,70,00,77,00,73,00,68,00,2e,00,65,00,78,00,\
65,00,22,00,20,00,22,00,25,00,31,00,22,00,00,00
[-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1\OpenWithList]
"a"="pwsh.exe"
"MRUList"="a"
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1\OpenWithProgids]
"ps1_auto_file"=hex(0):
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1\UserChoice]
"ProgId"="Applications\\pwsh.exe"
; Change "Edit" to open with Visual Studio Code, remove "Run with PowerShell".
; Assuming Code.exe is at "%LocalAppData%\Programs\Microsoft VS Code\Code.exe".
; --------------------------------------------------------------------
[-HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1]
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1]
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell]
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\Edit]
"NoSmartScreen"=""
; REG_EXPAND_SZ value of: "%LocalAppData%\Programs\Microsoft VS Code\Code.exe" "%1"
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\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
[-HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\.ps1]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\.ps1]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\.ps1\Shell]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\.ps1\Shell\Edit]
"NoSmartScreen"=""
; REG_EXPAND_SZ value of: "%LocalAppData%\Programs\Microsoft VS Code\Code.exe" "%1"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\.ps1\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
@AndrewS097
Copy link

Forsure I know you can modify the Run with PowerShell (name) if you modify the Muicache Computer\HKEY_CLASSES_ROOT\Local Settings\MuiCache, but there is no way to outright prevent it. Currently the .exe in MUICache is @"C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe ",-108. Please let me know if you figure out an alternative for removing it. ):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment