您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

详解python实现应用程序在右键菜单中添加打开方式步骤

2025/5/24 18:03:17发布22次查看
最近项目组开发的一个小工具想要在右键菜单中添加打开方式,以有道云笔记为例进行了需求拆解和代码编写
1.需求拆解:
如何实现手动添加右键菜单的打开方式:
step1:打开注册表编辑器,win+r->输入 “regedit”
step2:在hkey_classes_root/*/shell (或者hkey_local_machine/software/classes/*/shell ,两个目录是一样的) 添加一个key:ynote,然后在该项中新建项command,然后再编辑字符串,添加应用程序的路径,最后再路径和名称的后面加上空格和“%1”,然后在右键就可以找到ynote的打开方式
2.代码实现
method1:通过_winreg模块实现:
import _winreg from _winreg import key_all_access with _winreg.openkey(_winreg.hkey_local_machine, r"software\classes\*\shell") as key: print key newkey = _winreg.createkeyex(key,"ynote",0,key_all_access) sub_key = _winreg.openkey(_winreg.hkey_local_machine,r"software\classes\*\shell\ynote") newsubkey = _winreg.createkey(sub_key,"command") _winreg.setvalue(newsubkey,"(default)",1,"\"c:\program files (x86)\youdao\youdaonote\youdaonote.exe\" \"%1\"")
method2:通过win32api和win32con模块实现
import win32api import win32con key = win32api.regopenkey(win32con.hkey_local_machine,r"software\classes\*\shell") newkey = win32api.regcreatekey(key,"ynote") sub_key = win32api.regopenkey(win32con.hkey_local_machine,r"software\classes\*\shell\ynote") newsubkey = win32api.regcreatekey(sub_key,"command") win32api.regsetvalue(newsubkey,"(default)", win32con.reg_sz,"\"c:\program files (x86)\youdao\youdaonote\youdaonote.exe\" \"%1\"")
以上就是详解python实现应用程序在右键菜单中添加打开方式步骤的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product