Where to create context menu entry?
FILES
HKEY_CURRENT_USER\Software\Classes\*\shell\
Opens on a file
DIRECTORY
HKEY_CURRENT_USER\Software\Classes\Directory\shell
Opens on a directory
DIRECTORY_BACKGROUND HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell
Opens on the background of the Directory
DRIVE
HKEY_CURRENT_USER\Software\Classes\Drive\shell
Opens on the drives(think USBs)
The python script for commiting
import subprocess
import os
import re
import unicodedata
USER_NAMESPACE="YOUR_USER_NAME_HERE"
def slugify(value, allow_unicode=False):
"""
Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated
dashes to single dashes. Remove characters that aren't alphanumerics,
underscores, or hyphens. Convert to lowercase. Also strip leading and
trailing whitespace, dashes, and underscores.
"""
value = str(value)
if allow_unicode:
value = unicodedata.normalize('NFKC', value)
else:
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
value = re.sub(r'[^\w\s-]', '', value)
return re.sub(r'[-\s]+', '-', value).strip('-_')
'''
git init
git add .
git commit -m "Auto Publish"
git push –-set-upstream git@gitlab.example.com:namespace/nonexistent-project.git master
'''
if os.path.exists(os.path.join(os.getcwd(),'.git')):
print("ERROR: Git repo already exits")
exit(0)
current_folder_name=os.path.basename(os.getcwd())
current_folder_name=slugify(current_folder_name)
subprocess.run('git init -b main')
subprocess.run('git add .')
subprocess.run('git commit -m "Auto Publish"')
cmd='git push --set-upstream git@gitlab.com:'+USER_NAMESPACE+'/'+current_folder_name+'.git main'
subprocess.run(cmd)
print("SUCCESS!")
input()
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\Run Batch script]
@="&Run Batch script"
[HKEY_CLASSES_ROOT\Directory\shell\Run Batch script\command]
@="\"H:\\BATCH_FILE_PATH\\context-batch.bat\" \"%1\""
This only adds a context menu item for all directories/folders in Windows. If you want it showing for each and every file instead, you can use this:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Run script]
@="Run &script"
[HKEY_CLASSES_ROOT\*\shell\Run script\command]
@="\"H:\\BATCH_FILE_PATH\\context-batch.bat\" \"%1\""
Alternatively, you can add your batch script to the Send To item list by creating a shortcut to your batch script and placing it under %APPDATA%\Microsoft\Windows\SendTo (or enter shell:sendto into the address bar)
If you want your script to show in the context menu that appears when you right click on the empty space within a directory (directory background?) you can use the following REG file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\Run Batch script]
@="&Run Batch script"
"Icon"="%SystemRoot%\\System32\\shell32.dll,71"
[HKEY_CLASSES_ROOT\Directory\Background\shell\Run Batch script\command]
@="H:\\BATCH_FILE_PATH\\context-batch.bat \"%V\""
You don’t need the “Icon”="%SystemRoot%\System32\shell32.dll,71" line. It simply adds an icon to your context-menu.
Further moving….
Creating a singular context menu option
Before we get into the fancy stuff, let’s create a basic option. I will use the Directory Background location as an example. Our basic, unedited context menu might look something like this:
Let’s add an option called Open Command Prompt to open a command prompt in our current directory. The location for the Directory Background is HKEY_CLASSES_ROOT\Directory\Background\shell
, so let’s navigate there.
The steps to make a basic command in the registry are as follows:
- Create a new
key
under theshell
key. - Name the
key
what you want the command to be shown as, for me it will be “Open Command Prompt” - Right click the created
key
and add a newkey
calledcommand
(The sub key must be named command for it to work) - Change the default value of the
command
key to the code that should be ran when the command is selected(ex: cmd.exe)
Now we have an entry on our context menu that opens on the background of directories and opens a command prompt to the current location.
For the perfectionists out there, if you want to add an icon to the context menu entry, do as follows:
- Add a new key of type
String Value
calledIcon
to the base key - Set the value of the key to the path to the image in ICO format
Creating cascading context menus
Now that we have the basics covered, let’s get into some more advanced usage and create a cascading context menu.
A cascading context menu is a context menu that branches off into multiple options, possibly multiple times. Let’s create a context menu option that opens a list of programs as an example:
- The name of the command will be
Show Utilities
- It will cascade twice(two extra menus)
- It will open in
Directory Backgrounds
.
Steps to making a cascading Context menu
Create the base key in the same location as the Basic Command. The name of they key does not matter(It will not be the name of the option in the context menu)
Make sure the (default) key is at (value not set)
Add a new String Value to the key just created(type REG_SZ) and call it MUIVerb (type it exactly). Set the data of this variable to the name you want the base key to appear as on the context menu.
Add a new String value to the key and call it subcommands. Leave the value blank.
Create a key named shell in the key we just made:
If you want to create another sub menu, repeat steps 1–5 in the created shell key. If you nest multiple menus, you’ll have multiple shell keys. I’ll leave an example at the end.
To create a command that can be selected, it’s identical to creating a single context menu option but in the key we just created. Create a key in the shell key and name it what you want the option to appear as, I will call mine cmd for command prompt. In the created key, make another sub key called command and set the data of the command key to the command you wish to run upon selection.
Repeat steps 1–6 and 7 as many times as you wish.