Created
October 30, 2018 00:02
-
-
Save riverar/980120d7e3a13ed8b1d665cf974c8e31 to your computer and use it in GitHub Desktop.
Determine state of Quiet Hours/Focus Assist with WNF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Not to be used in any serious manner | |
// | |
#include <Windows.h> | |
#include <iostream> | |
#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0) | |
typedef struct _WNF_STATE_NAME | |
{ | |
ULONG Data[2]; | |
} WNF_STATE_NAME, *PWNF_STATE_NAME; | |
typedef struct _WNF_TYPE_ID | |
{ | |
GUID TypeId; | |
} WNF_TYPE_ID, *PWNF_TYPE_ID; | |
typedef const WNF_TYPE_ID *PCWNF_TYPE_ID; | |
typedef ULONG WNF_CHANGE_STAMP, *PWNF_CHANGE_STAMP; | |
extern "C" | |
NTSTATUS | |
NTAPI | |
NtQueryWnfStateData( | |
_In_ PWNF_STATE_NAME StateName, | |
_In_opt_ PWNF_TYPE_ID TypeId, | |
_In_opt_ const VOID* ExplicitScope, | |
_Out_ PWNF_CHANGE_STAMP ChangeStamp, | |
_Out_writes_bytes_to_opt_(*BufferSize, *BufferSize) PVOID Buffer, | |
_Inout_ PULONG BufferSize); | |
#pragma comment(lib, "ntdll.lib") | |
int wmain() | |
{ | |
// WNF_SHEL_QUIETHOURS_ACTIVE_PROFILE_CHANGED | |
// This wnf is signaled whenever active quiet hours profile / mode changes. | |
// The value is the restrictive level of an active profile and the restrictive level is unique per profile | |
// | |
WNF_STATE_NAME WNF_SHEL_QUIETHOURS_ACTIVE_PROFILE_CHANGED{ 0xA3BF1C75, 0xD83063E }; | |
WNF_CHANGE_STAMP unused_change_stamp{}; | |
DWORD buffer = 0; | |
ULONG buffer_size = sizeof(buffer); | |
if (NT_SUCCESS(::NtQueryWnfStateData(&WNF_SHEL_QUIETHOURS_ACTIVE_PROFILE_CHANGED, nullptr, nullptr, &unused_change_stamp, &buffer, &buffer_size))) | |
{ | |
std::cout << "Focus Assist status: "; | |
switch (buffer) | |
{ | |
case 0: | |
std::cout << "Off"; | |
break; | |
case 1: | |
std::cout << "On (Priority only)"; | |
break; | |
case 2: | |
std::cout << "On (Alarms only)"; | |
break; | |
default: | |
std::cout << "???"; | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment