Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get windows Quiet hours from Win32 or C# API

Tags:

c++

c#

winapi

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?

like image 463
Pankaj Avatar asked Feb 24 '16 10:02

Pankaj


People also ask

What does quiet hours mean on Windows 10?

Focus assist (also called quiet hours in earlier versions of Windows 10) allows you to avoid distracting notifications when you need to stay focused. It's set by default to activate automatically when you're duplicating your display, playing a game, or using an app in full screen mode.


3 Answers

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.

like image 88
Yoav Feuerstein Avatar answered Oct 18 '22 10:10

Yoav Feuerstein


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);
}
like image 2
eskimwier Avatar answered Oct 18 '22 09:10

eskimwier


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.

like image 1
wilx Avatar answered Oct 18 '22 09:10

wilx