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

2024-09-27 00:13:12 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我添加了以下注册表项:

[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

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


Tags: appspywindowscustomscriptssoftwareshellcommand
1条回答
网友
1楼 · 发布于 2024-09-27 00:13:12

我只是按照以下步骤操作,似乎很管用:

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)接下来编辑command子键的(Deafult)项的值,添加要执行的操作。在我的例子中,我想打开一个python文件,它告诉我有关该文件的详细信息:

这是python脚本:

import os
import sys

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

if __name__ == '__main__':
    main()

它位于C:\信息py在

这是我添加到default的条目:

python C:\\info.py %1

enter image description here

仅此而已,现在如果您右键单击zip文件,就会看到您添加的命令:

enter image description here

点击后显示:

enter image description here

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

更新-级联菜单

a)要添加级联菜单,请导航到上述步骤3中所述的键。在我的例子中,这是CompressedFolder\shell,它在HKEY_CLASSES\u根下。在这里添加一个具有您选择的名称的密钥,在我的例子中,我使用了CascadeMenu。向该键添加2个条目:

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

enter image description here

b)接下来我们需要告诉windows这个命令的实际作用。导航到:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\Shell

在这里添加一个带有命令名的键。在我的例子中,这个键被称为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

相关问题 更多 >

    热门问题