python - Windows 7 - Python 的右键单击上下文级联菜单

标签 python windows shell cascade

<分区>

我正在尝试添加到 *.zip 文件的上下文菜单。使用必要的参数启动我的 python 脚本。

我已添加以注册以下 key :

[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"

当菜单出现时,点击那些绝对没有任何作用。

我一直在学习本教程: http://msdn.microsoft.com/en-us/library/windows/desktop/hh127467%28v=vs.85%29.aspx

我遗漏了一些东西,但不幸的是我找不到答案。你能帮我吗?

最佳答案

我刚刚执行了这些步骤,它似乎有效:

1) 首先在HKEY_CLASSES_ROOT下找到.zip

2) 选择它并查看其默认值。在我的例子中,默认是 CompressedFolder:

enter image description here

3) 现在向下导航至 CompressedFolder\shell(或 .zip 的默认设置),它也包含在 HKEY_CLASSES_ROOT 下:

enter image description here

4) 右键单击​​ shell 并添加一个新键,在我的例子中,我添加了一个名为 MyCommand 的键。向该键添加一个名为 command 的子键。 MyCommand 将是出现在上下文菜单中的命令的名称。

enter image description here

5) 接下来编辑 mycommandcommand 子项的 (默认) 条目的值,添加您希望执行的操作.在我的例子中,我想打开一个 python 文件,它告诉我有关该文件的详细信息:

这是 python 脚本:

import os
import sys

def main():
    st = os.stat(sys.argv[1])
    print st
    raw_input()

if __name__ == '__main__':
    main()

它位于 C:\info.py

这是我添加到默认的条目:

python C:\\info.py %1

enter image description here

这就是它的全部内容,现在如果您右键单击一个 zip 文件,您应该会看到您添加的命令:

enter image description here

点击后给出:

enter image description here

希望这就是您想要的。如果您希望添加更多命令,则只需在 shell 键下添加更多子键,就像我们对 MyCommand 所做的那样。

更新 - 级联菜单

a) 为了添加级联菜单,请导航至上述步骤 3 中所述的键。在我的例子中,这是位于 HKEY_CLASSES_ROOT 下的 CompressedFolder\shell。在这里添加一个带有您选择的名称的键,在我的例子中,我使用了 CascadeMenu。向该键添加 2 个条目:

  • MUIVerb - 这是级联菜单的名称。在我的例子中,我使用了 MyCascadeMenu
  • SubCommands - 这是一个以分号分隔的命令列表。随意命名命令,在我的例子中,我使用了 python.info。使用“|”在命令之间,如果你想要一个分隔符,例如 command1;|;command2

enter image description here

b) 接下来我们需要告诉窗口这个命令实际上做了什么。导航到:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\Shell

在这里添加一个带有命令名称的键。在我的例子中, key 称为 python.info。将键的默认值设置为您希望在上下文菜单中显示的名称。在我的例子中,我使用了 "File Info"

enter image description here

c) 现在向您的命令添加一个子项,称为 command。将此命令的默认条目更改为您希望执行的命令。在我的例子中,我将它设置为 python C:\\info.py %1

enter image description here

d) 我们现在完成了,右键单击 .zip 文件以查看新创建的上下文菜单:

enter image description here

关于python - Windows 7 - Python 的右键单击上下文级联菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17989543/

相关文章:

python - 如何使用 Bokeh 网格图激活滚动?

python - 从 Pandas Dataframe 读取值时发生内存泄漏

python - 如何在Python中获得系统显示分辨率的宽高比?

c++ - 使c++程序在windows中的特定核心上运行

windows - 导航到分组 GridView 中的特定组标题(win store app)

android - 从 ADB/Shell 命令模拟强制停止

bash - 管道和重定向

python - 仅在 Python 的 OpenCV 轨迹栏上有奇数?

python - 如何在 Windows 上连接到 WiFi 网络?

linux - 将 Windows 批处理脚本转换为 Linux Shell 脚本