简体   繁体   中英

Get windows Quiet hours from Win32 or C# API

Windows introduced "Quiet Hours" OR "Do not disturb" feature from Windows version 8 onward. Using this feature, one can disable notifications popups for configured amount of time from task bar notification area.

I am trying to get current OS, Quiet hours within C++ or from C# application but haven't found any API or Event.

Can anybody help on this to resolve my issue?

Since a recent major update to Windows 10 , "Quiet Hours" has changed to "Focus Assist" - and it seems to work differently, so previous answers don't apply any more.

The only solution I could find for this so far, is the one offered here .

There is a registry value set to 0 during quiet hours named "NOC_GLOBAL_SETTINGS_TOASTS_ENABLED". Here is working code to determine if a user currently has quiet hours enabled:

public static bool IsQuietHours()
{
    string path = "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Notifications\\Settings";
    string key = "NOC_GLOBAL_SETTING_TOASTS_ENABLED";
    int? toastsEnabled = (int?)Microsoft.Win32.Registry.GetValue(path, key, 1);
    return (toastsEnabled == 0);
}

It seems to me that the original answer from @PhilWilliams, albeit it being link only answer, was correct:

You can query the state by using SHQueryUserNotificationState() function . See also QUERY_USER_NOTIFICATION_STATE enumeration for possible value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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