简体   繁体   English

软件运行时禁用通知 在 windows 10

[英]Disable notifications when software is running On windows 10

is there a way to disable notifications when a software is running?有没有办法在软件运行时禁用通知?

I am using tkinter (if it's relevant).我正在使用 tkinter (如果相关)。

Os is windows 10操作系统是 windows 10

Thanks!谢谢!

The web page here shows how to disable notifications by editing the registry. 此处的 web 页面显示了如何通过编辑注册表来禁用通知。

Given that, it should be possible to use the winreg module to query and set the pertinent key.鉴于此,应该可以使用 winreg 模块来查询和设置相关键。

Here's some sample code.这是一些示例代码。 This does not work for me on my current system, because I don't have my permission levels set to allow it ( I get "PermissionError: [WinError 5] Access is denied" on the winreg.SetValueEx call), so I can't test it, but it should give you some ideas of how to get there.这在我当前的系统上对我不起作用,因为我没有设置允许它的权限级别(我在winreg.SetValueEx调用上得到“PermissionError:[WinError 5] Access is denied”),所以我可以' t 测试它,但它应该给你一些关于如何到达那里的想法。 (Modifying the registry will, at a minimum, require running as admin. Last time I needed to do this, I followed the advice at Request UAC elevation from within a Python script? and it worked for me.) (修改注册表至少需要以管理员身份运行。上次我需要这样做时,我遵循了从 Python 脚本中请求 UAC 提升的建议?它对我有用。)

import winreg

app_name = "Microsoft.SkyDrive.Desktop"
notifications_key = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Notifications\\Settings'

keyname = notifications_key + "\\" + app_name

# check its value
regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, keyname)
try:
    enabled_setting = winreg.QueryValueEx(regkey, "Enabled")
    notification_enabled = enabled_setting[0] # 1 = enabled; 0 = not enabled
except FileNotFoundError:
    notification_enabled = None
winreg.CloseKey(regkey)
print(f"Enabled value: {notification_enabled}")

# disable notifications
regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, keyname, winreg.KEY_SET_VALUE)
winreg.SetValueEx(regkey, "Enabled", 0, winreg.REG_DWORD, 0)
winreg.CloseKey(regkey)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM