Python enables applications to add the open mode function in the context menu, and python context menu

Source: Internet
Author: User

Python enables applications to add the open mode function in the context menu, and python context menu

Recently, a small tool developed by the project team wants to add an open method in the right-click menu. The youdao cloud note is used as an example to describe the demand and compile the code.

1. Demand dismantling:

How to manually add the right-click menu to open the menu:

Step 1:Open Registry Editor, Win + R-> enter "regedit"

Step 2:Add a key: YNote in HKEY_CLASSES_ROOT/*/shell (or HKEY_LOCAL_MACHINE/SOFTWARE/Classes/*/shell with the same directory), and then create a new command in this item, then, edit the string, add the Application Path, add space and "% 1" after the path and name, and right-click the application to find the YNote opening method.

2. Code Implementation

Method1: implemented through the _ winreg module:

import _winregfrom _winreg import KEY_ALL_ACCESSwith _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Classes\*\shell") as key:print keynewKey = _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:Implemented through win32api and win32con Module

import win32apiimport win32conkey = 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\"")

The above section describes how to add the open mode function to the python implementation application in the right-click menu. I hope it will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.