Skip to content

Commit

Permalink
v3.9.7 删除旧启动项
Browse files Browse the repository at this point in the history
  • Loading branch information
baizhiren committed May 4, 2024
1 parent 22ac516 commit 3daed9d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion GUI/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from breakTimer.FileChecker import FileChecker
from breakTimer.Hook import Hook

app_name = "breakTimer3.9.6"
app_name = "breakTimer3.9.7"

# 打开注册表键

Expand Down Expand Up @@ -423,7 +423,29 @@ def read_configs(first_read=True):
key_path = r"Software\Microsoft\Windows\CurrentVersion\Run"
try:
reg = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_path, 0, winreg.KEY_READ)

def delete_matching_registry_values(key_path, pattern):
# 打开指定路径的注册表键
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_path, 0, winreg.KEY_ALL_ACCESS) as key:
i = 0
while True:
try:
# 枚举键中的每一个值
value_name, value_data, value_type = winreg.EnumValue(key, i)
# 检查值的名称是否符合模式
if value_name.startswith(pattern) and value_name != app_name:
print(f"Deleting: {value_name}")
winreg.DeleteValue(key, value_name)
else:
i += 1
except OSError:
# 当索引超出范围时,停止遍历
break
# 使用函数,指定键路径和要匹配的模式
pattern = 'breakTimer'
delete_matching_registry_values(key_path, pattern)
value, value_type = winreg.QueryValueEx(reg, app_name)

print(value, value_type)
winreg.CloseKey(reg)
print('自启项已存在')
Expand Down

0 comments on commit 3daed9d

Please sign in to comment.