1- from winreg import OpenKey , HKEY_CURRENT_USER , QueryValueEx , DeleteValue , CloseKey , KEY_ALL_ACCESS , SetValueEx , REG_SZ
1+ import winreg
22import wx .adv
33from pycaw .pycaw import AudioUtilities , ISimpleAudioVolume
44from core .config import Config
@@ -30,31 +30,58 @@ def check_update():
3030
3131 return latest_release
3232
33- def modifyStartup (name : str , file_path : str ):
34- key = OpenKey (HKEY_CURRENT_USER , "Software\Microsoft\Windows\CurrentVersion\Run" , 0 , KEY_ALL_ACCESS )
33+ def addStartup (program_name , program_path ):
34+ """
35+ 将程序添加到开机自启动
36+
37+ :param program_name: 注册表中的程序名称
38+ :param program_path: 程序的完整路径
39+ """
40+ # 打开注册表中的自启动项
41+ key = winreg .HKEY_CURRENT_USER
42+ key_path = r"Software\Microsoft\Windows\CurrentVersion\Run"
43+
3544 try :
36- existing_value , _ = QueryValueEx (key , name )
45+ # 打开注册表键
46+ registry_key = winreg .OpenKey (key , key_path , 0 , winreg .KEY_WRITE )
47+ # 设置注册表项
48+ winreg .SetValueEx (registry_key , program_name , 0 , winreg .REG_SZ , program_path )
49+ # 关闭注册表键
50+ winreg .CloseKey (registry_key )
51+ return True
52+ except WindowsError as e :
53+ return False
3754
38- if existing_value == file_path :
39- DeleteValue (key , name )
40- CloseKey (key )
41- return "Removed"
42- else :
43- SetValueEx (key , name , 0 , REG_SZ , file_path )
44- return "Added"
45- except WindowsError :
46- SetValueEx (key , name , 0 , REG_SZ , file_path )
47- return "Added"
55+ def removeStartup (program_name ):
56+ """
57+ 从开机自启动中移除程序
58+
59+ :param program_name: 注册表中的程序名称
60+ """
61+ # 打开注册表中的自启动项
62+ key = winreg .HKEY_CURRENT_USER
63+ key_path = r"Software\Microsoft\Windows\CurrentVersion\Run"
64+
65+ try :
66+ # 打开注册表键
67+ registry_key = winreg .OpenKey (key , key_path , 0 , winreg .KEY_WRITE )
68+ # 删除注册表项
69+ winreg .DeleteValue (registry_key , program_name )
70+ # 关闭注册表键
71+ winreg .CloseKey (registry_key )
72+ return True
73+ except WindowsError as e :
74+ return False
4875
4976def checkStartup (name : str , file_path : str ):
5077 """
5178 Check if the startup key exists and if it points to the correct file path
5279
5380 returns True if the key exists and points to the correct file path
5481 """
55- key = OpenKey (HKEY_CURRENT_USER , "Software\Microsoft\Windows\CurrentVersion\Run" , 0 , KEY_ALL_ACCESS )
82+ key = winreg . OpenKey (winreg . HKEY_CURRENT_USER , "Software\Microsoft\Windows\CurrentVersion\Run" , 0 , winreg . KEY_READ )
5683 try :
57- existing_value , _ = QueryValueEx (key , name )
84+ existing_value , _ = winreg . QueryValueEx (key , name )
5885
5986 if existing_value == file_path :
6087 return True
@@ -79,6 +106,21 @@ def changeMute(hwnd,flag=1):
79106 except :
80107 pass
81108
109+ def remove_duplicates (input_list : list ):
110+ """
111+ Remove duplicates from a list while preserving the order.
112+
113+ input_list: list, the list from which to remove duplicates
114+ returns: list, the list without duplicates
115+ """
116+ seen = set ()
117+ output_list = []
118+ for item in input_list :
119+ if item not in seen :
120+ seen .add (item )
121+ output_list .append (item )
122+ return output_list
123+
82124def hwnd2processName (hwnd ):
83125 """
84126 从窗口句柄获取进程名称
0 commit comments