Skip to content

Instantly share code, notes, and snippets.

@MikeYEG
Forked from KyleMit/archive.ps1
Created September 16, 2020 16:51
Show Gist options
  • Save MikeYEG/a28e00cd2cf8e3b3c1b5b4fd4b0d2320 to your computer and use it in GitHub Desktop.
Save MikeYEG/a28e00cd2cf8e3b3c1b5b4fd4b0d2320 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