Skip to content

Instantly share code, notes, and snippets.

@KyleMit
Last active February 25, 2024 14:25
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save KyleMit/978086ae267ff5be17811e99c9607986 to your computer and use it in GitHub Desktop.
Save KyleMit/978086ae267ff5be17811e99c9607986 to your computer and use it in GitHub Desktop.
Execute Powershell Script on Right Click in Windows Explorer

When you double click a .reg file, it will automatically install in the registry (cmd regedit)

The basic registry pattern is:

HKEY_CLASSES_ROOT\Directory\Shell\<Script_Name>
HKEY_CLASSES_ROOT\Directory\Shell\<Script_Name>\command

Adding the \Background to the key will also add the context menu to an already open folder

HKEY_CLASSES_ROOT\Directory\Background\Shell\<Script_Name>
HKEY_CLASSES_ROOT\Directory\Background\Shell\<Script_Name>\command

Characters in the command need to be escaped twice, once on parsing into the registry, and once on execution

Available commands to pass are %L or %V

$path = $args[0]
Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show("Hello $path")
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\archive_script]
@="&Archive Folder"
[HKEY_CLASSES_ROOT\Directory\shell\archive_script\command]
@="C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -File \"C:\\scripts\\archive\\archive.ps1\" \"%L\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment