Windows 7 - Right-click context cascade menu for Python
cascade, python, shell, windows
Solution
I've just followed these steps and it appears to work:
1) First find the `.zip` key under `HKEY_CLASSES_ROOT`.
2) Select it and look at its default. In my case the default is `CompressedFolder`:
3) Now navigate your way down to `CompressedFolder\shell` (or what was ever under your default for .zip) which is also contained under `HKEY_CLASSES_ROOT`:
4) Right click on the shell and add a new key, in my case I've added a key named `MyCommand`. Add a subkey to this key called `command`. `MyCommand` will be the name of the command that appears on the context menu.
5) Next edit the value of the `(Deafult)` entry of the `command` subkey for `mycommand`, adding the operation you wish to perform. In my case I want to open a python file which tells me details about the file:
This is the python script:
import os
import sys
def main():
st = os.stat(sys.argv[1])
print st
raw_input()
if __name__ == '__main__':
main()
And it is located at C:\info.py
And this is the entry I've added to default:
`python C:\\info.py %1`
That's all there is to it, now if you were to right click on a zip file you should see the command you've added:
Which when clicked gives:
Hope this is what you where after. If you wish to add more commands then just add more subkeys under the `shell` key as we did with `MyCommand`.
UPDATE - CASCADING MENUS
a) In order to add cascading menus navigate to the key stated above in step 3. In my case this is `CompressedFolder\shell` which is under HKEY_CLASSES_ROOT. Once here add a key with a name of your choice, in my case I used `CascadeMenu`. Add 2 entries to this key:
- `MUIVerb` - this is the name that will appear for the cascade menu. In my case I have used `MyCascadeMenu`
- `SubCommands` - this is a semicolon separated list of commands. Name the commands whatever you like, in my case I have used `python.info`. Use a '|' between commands if you want a separator, for example `command1;|;command2`
b) Next we need to tell windows what this command actually does. Navigate to: `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\Shell`
Once here add a key with the name of your command. In my case the key is called `python.info`. Set the default value of the key to the name you want to appear in the context menu. In my case I have used `"File Info"`
c) Now add a subkey to your command, called `command`. Change the default entry of this command to the command you wish to execute. In my case I have set it to `python C:\\info.py %1`
d) We are now finished, right click on the .zip file to see your newly created context menu:
Problem
I'm trying to add to context menu for *.zip files. To launch my python script with nessesary parameters. I've added to register following keys: ``` [HKEY_CLASSES_ROOT\WinZip\shell\SSSeracher] "MUIVerb"="SSSearcher Script" "SubCommands"="SSSearcher.Rule1;SSSearcher.Rule2;SSSearcher.Rule3;SSSearcher.Custom;SSSearcher.Config" [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Rule1] @="Rule #1" [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Rule1\command] @="C:\\APPS\\python\\Scripts\\sssearcher.py \"%1\" \"1\"" [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Rule2] @="Rule #2" [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Rule2\command] @="C:\\APPS\\python\\Scripts\\sssearcher.py \"%1\" \"2\"" [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Rule3] @="Rule #3" [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Rule3\command] @="C:\\APPS\\python\\Scripts\\sssearcher.py \"%1\" \"3\"" [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Custom] @="Custom rule" [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Custom\command] @="C:\\APPS\\python\\Scripts\\sssearcher.py \"%1\" \"4\"" [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Custom] @="Custom rule" [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Custom\command] @="C:\\APPS\\python\\Scripts\\sssearcher.py \"%1\" \"4\"" [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Config] @="Config File" [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Config\command] @="vim C:\\APPS\\python\\Scripts\\sssearcher.pyc" ``` As menu showing up clickin on those does absolutly nothing. I've been following this tutorial: http://msdn.microsoft.com/en-us/library/windows/desktop/hh127467%28v=vs.85%29.aspx There is something that I missing, but unfortunately I cannot find answer what. Could you help me with that?