Configure Windows Creators Update Night Light via Registry

13

8

How can the new Night Light feature in Windows 10 (Pro) Creators Update be configured via the registry?

I'd like to auto configure new/updated installations when using my configuration management tool of choice (Chef). System inspection via Sysinternals Process Monitor shows a binary Data key getting updated deep in HKCU\Software\Microsoft\Windows\CurrentVersion\CloudStore\Cache\DefaultAccount\$$windows.data.bluelightreduction.settings\Current, but that's a big REG_BINARY blob and not very useful.

Help on a different registry, PowerShell, or other automation friendly way to configure the Night Light feature would be most appreciated!

David F. Severski

Posted 2017-04-16T15:41:57.467

Reputation: 240

use RegfromApp to trace it better. it generates the .reg file. maybe it can decode it

– magicandre1981 – 2017-04-16T16:48:20.870

Thanks for the suggestion @magicandre198. Process Monitor gives me the exact key and value being changed. The problem is the key is a binary one and there's no decoding documentation available for how that data key is built. Given the funky path in question, this may not be a section that is intended for direct modification (perhaps a cached settings location). I'm hoping someone has a line on management of the new Night Light feature as there doesn't seem to be much information on it so far. – David F. Severski – 2017-04-17T14:14:35.357

as I said, use Regfromapp, it generates .reg files for every change. – magicandre1981 – 2017-04-18T15:27:46.140

1

We may be talking at cross-purposes here. :) I know the key and the contents of the key being adjusted. It's just an awkward blob with no documentation. I've found https://github.com/jaapbrasser/SharedScripts/tree/master/Set-BlueLight which does a bit of hacking to provide a PS interface to the feature, but it's not clear how to combine the various settings together. I'm really looking for documentation (and an interface) on how this binary string is put together.

– David F. Severski – 2017-04-18T21:31:21.310

Answers

12

With a bunch of experimentation, I managed to more or less work out the format of that Registry value (see below for the details on that).

I made this PowerShell script:

Function Set-BlueLightReductionSettings {
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory=$true)] [ValidateRange(0, 23)] [int]$StartHour,
        [Parameter(Mandatory=$true)] [ValidateSet(0, 15, 30, 45)] [int]$StartMinutes,
        [Parameter(Mandatory=$true)] [ValidateRange(0, 23)] [int]$EndHour,
        [Parameter(Mandatory=$true)] [ValidateSet(0, 15, 30, 45)] [int]$EndMinutes,
        [Parameter(Mandatory=$true)] [bool]$Enabled,
        [Parameter(Mandatory=$true)] [ValidateRange(1200, 6500)] [int]$NightColorTemperature
    )
    $data = (2, 0, 0, 0)
    $data += [BitConverter]::GetBytes((Get-Date).ToFileTime())
    $data += (0, 0, 0, 0, 0x43, 0x42, 1, 0)
    If ($Enabled) {$data += (2, 1)}
    $data += (0xCA, 0x14, 0x0E)
    $data += $StartHour
    $data += 0x2E
    $data += $StartMinutes
    $data += (0, 0xCA, 0x1E, 0x0E)
    $data += $EndHour
    $data += 0x2E
    $data += $EndMinutes
    $data += (0, 0xCF, 0x28)
    $tempHi = [Math]::Floor($NightColorTemperature / 64)
    $tempLo = (($NightColorTemperature - ($tempHi * 64)) * 2) + 128
    $data += ($tempLo, $tempHi)
    $data += (0xCA, 0x32, 0, 0xCA, 0x3C, 0, 0)
    Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache\DefaultAccount\$$windows.data.bluelightreduction.settings\Current' -Name 'Data' -Value ([byte[]]$data) -Type Binary
}

To use it, save it as a .ps1 file and follow the instructions in the Enabling Scripts section of the PowerShell tag wiki. You can then import the script's contents by dot-sourcing:

. ./bluelightmanagement.ps1

And then use the cmdlet-like function that it supplies:

Set-BlueLightReductionSettings -StartHour 7 -StartMinutes 0 -EndHour 21 -EndMinutes 15 -Enabled $true -NightColorTemperature 6000

the results

The Settings app even updates everything (except the color slider) immediately if you have the blue light reduction page open when you run the command.

The format

  • 4 constant bytes - seemingly a signature common to all CloudStore values
  • The last-modified time of the setting as a 64-bit FILETIME value (8 bytes, little endian)
  • 8 more constant bytes
  • The bytes 2 then 1 if the blue light reduction feature is enabled, just gone if it's disabled
  • 3 more constant bytes
  • The start time's hour (1 byte)
  • 1 constant byte
  • The start time's minutes (1 byte)
  • 4 constant bytes
  • The end time's hour (1 byte)
  • 1 constant byte
  • The end time's minutes (1 byte)
  • 3 constant bytes
  • The night-time color temperature in Kelvin, after some weird binary math (2 bytes)
  • 7 constant bytes

The color temperature is stored as two bytes in little endian. The high-value one is the integer part of the result of dividing the temperature by 64. The low-value byte is the remainder multiplied by two, then added to 128. To calculate the temperature from the bytes, multiply the high byte by 64 and add what you get when you divide by two the difference between the low byte and 128.

Ben N

Posted 2017-04-16T15:41:57.467

Reputation: 32 973

I am trying to write a script to only toggle on and off the night light. If I'm not mistaken, the bytes 20 and 21 should indicate if the feature is on (according to your description at least since 4 + 8 + 8 = 20) but when I look at the registry entry using regedit, I don't see bytes 21 change, I don't see any change at all for that matter. I've made sure I refresh the regedit window with F5 and even reopened it after I have toggled the night light feature from the UI. Do you have an idea of what is going on? – Gaboik1 – 2018-01-02T04:29:19.397

1

I have also found, using this utility from NirSoft http://www.nirsoft.net/articles/find_modified_time_registry_key.html , that the registry key that you specified isn't being modified at all when I activate and deactivate the night light feature. Perhaps Microsoft changed it in the last update?

– Gaboik1 – 2018-01-02T06:25:05.497

1@Gaboik1 This Registry value is kind of strange in that its layout changes a lot; the format I described is just one that works, not necessarily the only one. I don't know of a way to consistently read the data out of this value, but I tested on Windows 10 1709 and using this script to set the settings still works. – Ben N – 2018-01-02T15:45:51.640

Writing this in .net, I found to actually use schedule (vs your code, which seems to do by sunrise/sunset) I had to add bytes 0xC2,0x0A,0x00 just before CA 14 0E. Then it would trigger and set it to hours based. Otherwise it worked. On 1709. – Mgamerz – 2018-08-30T22:03:26.890

@Mgamerz Can confirm this is correct, and works in 1809. Have placed an edit on the answer. – metamorphosis – 2019-04-03T00:13:57.430

As of today, last update, this doesn't work anymore. The registry key modified is \Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\DefaultAccount\Current\default$windows.data.bluelightreduction.settings\windows.data.bluelightreduction.settings\Data and sadly the binary format is not the same. – Julien__ – 2019-10-02T13:36:24.123

Why won't Windows provide a nice CLI interface to change settings ???? – Julien__ – 2019-10-02T13:37:54.007

2

Several hours of experiments and voila:
How to turn Night Light on/off in Win10 1903

The Registry key is:

HKCU\Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\DefaultAccount\Current\default$windows.data.bluelightreduction.bluelightreductionstate\windows.data.bluelightreduction.bluelightreductionstate\

Value name: Data

To enable Night Light:

  1. Add bytes "10" and "00" to Data on 24 and 25 indexes respectively so all data length increases (don't change existing values, just add two more bytes)
  2. Increment value in 11 or 12 indexes by 1 (for example: if it was FF 01 than now it needs to be 00 02 respectively) Actually it seems it's time here and it's written in 8 bytes in little endian format, so you'll need also 13, 14, 15, 16, 17 and 18 indexes if you want to do it precise.

To disable Night Light:

  1. Remove bytes "10" and "00" from Data on 24 and 25 indexes respectively so all data length decreases
  2. Increment value in 11 or 12 indexes by 1 (for example: if it was FF 01 than now it needs to be 00 02 respectively)

I only needed to turn Night Light on/off for my program, so unfortunately all other options still need research. But it seems that the key option to all other tweaks to work (like changing temperature and schedule) is to properly increment time. These mods need to be done in another Data value in neighboring registry key windows.data.bluelightreduction.settings.

hgrev

Posted 2017-04-16T15:41:57.467

Reputation: 21