Toggling Focus Assist mode in Win 10 Programmatically

You can toggle the mode using WNF mechanism.

Generate binary content of the file "0" = 00 00 00 00 (hex) and file "1" = 02 00 00 00 (hex)

For example, in git bash

echo -n -e "\x00\x00\x00\x00" > 0
echo -n -e "\x02\x00\x00\x00" > 1

Clone repository: https://github.com/ionescu007/wnfun

pip install Pywin32
pip install hexdump

Turn on the Priority mode

python WnfDump.py -w WNF_SHEL_QUIET_MOMENT_SHELL_MODE_CHANGED 1

Turn off Focus Assist

python WnfDump.py -w WNF_SHEL_QUIET_MOMENT_SHELL_MODE_CHANGED 0

If you find a way to turn on the "Alarms only" mode, let me know.

You can use the same technique C++ as well.

EDIT: Actually, the command activates mode that is set for the "full screen mode" and the file content 01 00 00 00, would activate the "game mode". If both are turned off, the command will have no effect.


Like Pavel Henrykhsen answer says, there is one programmatic, albeit undocumented and unsupported way of doing it. Here is an implementation, albeit written in Rust.

The relevant function is the ZwUpdateWnfStateData from the ntdll.dll. In this case, the relevant arguments are

  1. The ID of the state, which I managed to find at https://github.com/googleprojectzero/sandbox-attacksurface-analysis-tools/blob/80d7fcc8df9c3160c814c60f5121ae46c560a1b5/NtApiDotNet/NtWnfWellKnownNames.cs#L865
  2. A buffer with the values [0x02, 0x00, 0x00, 0x00]
  3. The length of the buffer

All arguments after that can be safely ignored.

// Pseudo-code
ZwUpdateWnfStateData(
            0xd83063ea3bf5075UL,
            new byte[] {0x02, 0x00, 0x00, 0x00},
            4,
            0,
            0,
            0,
            0,
        );

This does seem to rely on the "when I'm using an app in full-screen" setting being turned on in the focus mode settings.

Also, if one attempts to use this to enable focus mode, I recommend first disabling focus mode (pass new byte[] {0x00, 0x00, 0x00, 0x00} instead). Then, after a few milliseconds, one can safely enable focus mode.


I am looking to toggle Focus Assist mode in Win 10 programmatically and have thus far been unsuccessful

Currently, UWP does not provide such api to switch Focus Assist mode programmatically . If you do want this feature, please feel free to ask for this feature on UserVoice.