Skip to content

Instantly share code, notes, and snippets.

@KyleMit KyleMit/archive.ps1
Last active May 7, 2020

Embed
What would you like to do?
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
You can’t perform that action at this time.