Last active
September 21, 2019 23:57
-
-
Save riverar/085d98ffb1343e92225a10817109b2e3 to your computer and use it in GitHub Desktop.
Example demonstrating how to retrieve the current Focus Assist profile's Priority Apps list (https://withinrafael.com/2019/09/19/determine-if-your-app-is-in-a-focus-assist-profiles-priority-list/)
This file contains hidden or 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
// © Rafael Rivera | |
// License: MIT | |
import "oaidl.idl"; | |
[uuid(e0b5ef8b-a9b4-497a-8f71-08dd5c8ab2bf)] | |
library QuietHours | |
{ | |
[uuid(f53321fa-34f8-4b7f-b9a3-361877cb94cf)] | |
coclass QuietHoursSettings | |
{ | |
[default] interface IQuietHoursSettings; | |
} | |
[uuid(af86e2e0-b12d-4c6a-9c5a-d7aa65101e90)] | |
interface IQuietMoment : IUnknown | |
{ | |
// Incomplete | |
} | |
[uuid(e813fe81-62b6-417d-b951-9d2e08486ac1)] | |
interface IQuietHoursProfile : IUnknown | |
{ | |
[propget] HRESULT DisplayName([out, string, retval] LPWSTR* displayName); | |
[propget] HRESULT ProfileId([out, string, retval] LPWSTR* profileId); | |
HRESULT GetSetting(int setting, [out, retval] int* value); | |
HRESULT PutSetting(int setting, int value); | |
[propget] HRESULT IsCustomizable([out, retval] BOOL* result); | |
HRESULT GetAllowedContacts([out] UINT32* count, [out, retval] LPWSTR* allowedContacts); | |
HRESULT AddAllowedContact([in, string] LPWSTR allowedContact); | |
HRESULT RemoveAllowedContact([in, string] LPWSTR allowedContact); | |
HRESULT GetAllowedApps([out] UINT32* count, [out, retval] LPWSTR** allowedApps); | |
HRESULT AddAllowedApp([in, string] LPWSTR allowedApp); | |
HRESULT RemoveAllowedApp([in, string] LPWSTR allowedApp); | |
[propget] HRESULT Description([out, string, retval] LPWSTR* description); | |
[propget] HRESULT CustomizeLinkText([out, string, retval] LPWSTR* linkText); | |
[propget] HRESULT RestrictiveLevel([out, string, retval] LPWSTR* restrictiveLevel); | |
} | |
[uuid(cd86a976-8ea9-404b-a197-42e73dbaa901)] | |
interface IQuietHoursPinnedContactManager : IUnknown | |
{ | |
HRESULT GetPinnedContactList([out] UINT32* count, [out, string, retval] LPWSTR* pinnedContacts); | |
} | |
[uuid(b0217783-87b7-422c-b902-5c148c14f150)] | |
interface IQuietMomentsManager : IUnknown | |
{ | |
HRESULT GetAllQuietMomentModes([out] UINT32* count, [out, retval] UINT32** quietMomentModes); | |
HRESULT GetQuietMoment([in] UINT32 quietMomentId, [out, retval] IQuietMoment** quietMoment); | |
HRESULT TurnOffCurrentlyActiveQuietMoment(); | |
HRESULT GetActiveQuietMoment([out, retval] UINT32* quietMomentId); | |
} | |
typedef struct _QH_PROFILE_DATA | |
{ | |
// Incomplete | |
} QH_PROFILE_DATA; | |
[uuid(6bff4732-81ec-4ffb-ae67-b6c1bc29631f)] | |
interface IQuietHoursSettings : IUnknown | |
{ | |
[propget] HRESULT UserSelectedProfile([out, string, retval] LPWSTR* profileId); | |
[propput] HRESULT UserSelectedProfile([in] LPWSTR profileId); | |
HRESULT GetProfile([in, string] LPWSTR profileId, [out, retval] IQuietHoursProfile**); | |
HRESULT GetAllProfileData(UINT32* count, QH_PROFILE_DATA*); | |
HRESULT GetDisplayNameForProfile([in, string] LPWSTR profileId, [out, string, retval] LPWSTR* displayName); | |
[propget] HRESULT QuietMomentsManager([out, retval] IQuietMomentsManager**); | |
[propget] HRESULT OffProfileId([out, string, retval] LPWSTR* profileId); | |
[propget] HRESULT ActiveQuietMomentProfile([out, string, retval] LPWSTR* profileId); | |
[propput] HRESULT ActiveQuietMomentProfile([in] LPWSTR profileId); | |
[propget] HRESULT ActiveProfile([out, string, retval] LPWSTR* profileId); | |
[propget] HRESULT QuietHoursPinnedContactManager([out, retval] IQuietHoursPinnedContactManager**); | |
[propput] HRESULT QuietMomentsShowSummaryEnabled([out, retval] BOOL* isEnabled); | |
HRESULT GetAlwaysAllowedApps([out] UINT32* count, [out, string, retval] LPWSTR** allowedApps); | |
HRESULT StartProcessing(); | |
HRESULT StopProcessing(); | |
} | |
} |
This file contains hidden or 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
// © Rafael Rivera | |
// License: MIT | |
#include <iostream> | |
#include <windows.h> | |
#include <atlbase.h> | |
#include "quiethours_h.h" | |
void ThrowIfFailed(HRESULT hr) | |
{ | |
if (FAILED(hr)) | |
{ | |
DebugBreak(); | |
throw std::system_error{ hr, std::system_category() }; | |
} | |
} | |
int wmain() | |
{ | |
ThrowIfFailed(CoInitialize(nullptr)); | |
CComPtr<IQuietHoursSettings> quietHoursSettings; | |
ThrowIfFailed(CoCreateInstance(CLSID_QuietHoursSettings, nullptr, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&quietHoursSettings))); | |
CComHeapPtr<wchar_t> profileId; | |
ThrowIfFailed(quietHoursSettings->get_UserSelectedProfile(&profileId)); | |
std::wcout << L"Current profile: " << static_cast<LPWSTR>(profileId) << std::endl << std::endl; | |
CComPtr<IQuietHoursProfile> profile; | |
ThrowIfFailed(quietHoursSettings->GetProfile(profileId, &profile)); | |
uint32_t count = 0; | |
{ | |
CComHeapPtr<LPWSTR> apps; | |
ThrowIfFailed(profile->GetAllowedApps(&count, &apps)); | |
std::wcout << L"Allowed apps: " << std::endl; | |
for (uint32_t i = 0; i < count; i++) | |
{ | |
CComHeapPtr<wchar_t> aumid; // Wrapped for CoTaskMemFree on scope exit | |
aumid.Attach(apps[i]); | |
std::wcout << static_cast<LPWSTR>(aumid) << std::endl; | |
} | |
} | |
} |
This file contains hidden or 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
// © Rafael Rivera | |
// License: MIT | |
using System; | |
using System.Runtime.InteropServices; | |
namespace QuietHoursSample | |
{ | |
[ComImport] | |
[Guid("F53321FA-34F8-4B7F-B9A3-361877CB94CF")] | |
class QuietHoursSettings { } | |
[Guid("6BFF4732-81EC-4FFB-AE67-B6C1BC29631F")] | |
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | |
interface IQuietHoursSettings | |
{ | |
string UserSelectedProfile | |
{ | |
[return: MarshalAs(UnmanagedType.LPWStr)] get; | |
[param: MarshalAs(UnmanagedType.LPWStr)] set; | |
} | |
IQuietHoursProfile GetProfile([MarshalAs(UnmanagedType.LPWStr)] string profile); | |
void GetAllProfileData(); /* Incomplete definition */ | |
[return: MarshalAs(UnmanagedType.LPWStr)] | |
string GetDisplayNameForProfile([MarshalAs(UnmanagedType.LPWStr)] string profile); | |
IntPtr QuietMomentsManager { get; } /* Incomplete definition */ | |
string OffProfileId { [return: MarshalAs(UnmanagedType.LPWStr)] get; } | |
string ActiveQuietMomentProfile | |
{ | |
[return: MarshalAs(UnmanagedType.LPWStr)] get; | |
[param: MarshalAs(UnmanagedType.LPWStr)] set; | |
} | |
string ActiveProfile { [return: MarshalAs(UnmanagedType.LPWStr)] get; } | |
IntPtr QuietHoursPinnedContactManager { get; } /* Incomplete definition */ | |
void SetQuietMomentsShowSummaryEnabled([MarshalAs(UnmanagedType.Bool)] bool isEnabled); | |
[return: MarshalAs(UnmanagedType.Bool)] | |
bool GetQuietMomentsShowSummaryEnabled(); | |
IntPtr GetAlwaysAllowedApps(out uint count); | |
void StartProcessing(); | |
void StopProcessing(); | |
} | |
[Guid("e813fe81-62b6-417d-b951-9d2e08486ac1")] | |
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | |
interface IQuietHoursProfile | |
{ | |
[return: MarshalAs(UnmanagedType.LPWStr)] | |
string GetDisplayName(); | |
[return: MarshalAs(UnmanagedType.LPWStr)] | |
string GetProfileId(); | |
IntPtr GetSetting(int setting); /* Incomplete definition */ | |
IntPtr SetSetting(int setting, int value); /* Incomplete definition */ | |
[return: MarshalAs(UnmanagedType.Bool)] | |
bool GetIsCustomizable(); | |
void GetAllowedContacts(); /* Incomplete definition */ | |
void AddAllowedContact(); /* Incomplete definition */ | |
void RemoveAllowedContact(); /* Incomplete definition */ | |
IntPtr GetAllowedApps([Out] out uint numAllowedApps); | |
void AddAllowedApp(); /* Incomplete definition */ | |
void RemoveAllowedApp(); /* Incomplete definition */ | |
void GetDescription(); /* Incomplete definition */ | |
void GetCustomizeLinkText(); /* Incomplete definition */ | |
void GetRestrictiveLevel(); /* Incomplete definition */ | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var settings = (IQuietHoursSettings)new QuietHoursSettings(); | |
var profileId = settings.GetUserSelectedProfile(); | |
var profile = settings.GetProfile(profileId); | |
var aumidArrayPtr = profile.GetAllowedApps(out var numberOfAllowedApps); | |
Console.WriteLine($"The '{profile.GetDisplayName()}' profile allows the following app AUMIDs through:"); | |
Console.WriteLine(); | |
for (int i = 0; i < numberOfAllowedApps; i++) | |
{ | |
Console.WriteLine(Marshal.PtrToStringUni(Marshal.ReadIntPtr(aumidArrayPtr + (IntPtr.Size * i)))); | |
} | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment