Configure Windows Creators Update Night Light via Registry

14,496

Solution 1

With a bunch of experimentation, I managed to more or less work out the format of that Registry value and wrote a PowerShell script to set it.

Tested on 21H2

And possibly appropriate for versions as early as the 2019 updates.

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 = (0x43, 0x42, 0x01, 0x00, 0x0A, 0x02, 0x01, 0x00, 0x2A, 0x06)
    $epochTime = [System.DateTimeOffset]::new((date)).ToUnixTimeSeconds()
    $data += $epochTime -band 0x7F -bor 0x80
    $data += ($epochTime -shr 7) -band 0x7F -bor 0x80
    $data += ($epochTime -shr 14) -band 0x7F -bor 0x80
    $data += ($epochTime -shr 21) -band 0x7F -bor 0x80
    $data += $epochTime -shr 28
    $data += (0x2A, 0x2B, 0x0E, 0x1D, 0x43, 0x42, 0x01, 0x00)
    If ($Enabled) {$data += (0x02, 0x01)}
    $data += (0xCA, 0x14, 0x0E)
    $data += $StartHour
    $data += 0x2E
    $data += $StartMinutes
    $data += (0x00, 0xCA, 0x1E, 0x0E)
    $data += $EndHour
    $data += 0x2E
    $data += $EndMinutes
    $data += (0x00, 0xCF, 0x28)
    $data += ($NightColorTemperature -band 0x3F) * 2 + 0x80
    $data += ($NightColorTemperature -shr 6)
    $data += (0xCA, 0x32, 0x00, 0xCA, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00)
    Set-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\CloudStore\Store\DefaultAccount\Current\default$windows.data.bluelightreduction.settings\windows.data.bluelightreduction.settings' -Name 'Data' -Value ([byte[]]$data) -Type Binary
}

The format (or more properly a working format, since the Settings app can create multiple slightly different layouts):

  • 10 constant bytes
  • The last-modified Unix timestamp in seconds, mangled and spread across 5 bytes in what is probably a variable-length encoding:
    • One byte whose bits 0-6 are the timestamp's bits 0-6 but whose top bit 7 is always set
    • One byte whose bits 0-6 are the timestamps' 7-13 but whose top bit is always set
    • Likewise for two more sets of 7 bits
    • One final byte for timestamp bits 28-31, top bit not set
  • 8 constant bytes
  • Only if the schedule is enabled: constant bytes 0x02, 0x01
  • 3 constant bytes
  • The start hour
  • The constant byte 0x2E (presumably a field delimiter or type)
  • The start minute
  • 4 constant bytes
  • The end hour
  • The constant byte 0x2E again
  • 3 constant bytes
  • The night color temperature in Kelvin, two mangled bytes:
    • One byte whose low bit 0 is always unset, bits 1-6 are the temperature's bits 0-5, and top bit 7 is always set
    • One byte for the temperature's bit 6 and above, top bit not set
  • 10 constant bytes

Tested on 1703/1709

And possibly working as late as the 2018 updates.

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 += (0xC2, 0x0A, 0x00) # Some users have reported this line necessary on 1709, was not needed originally
    $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
    # Alternate proposed version (see edit history), possibly version-specific?: $tempLo = ($NightColorTemperature - ($tempHi * 64)) * 4
    $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
}

Using it

Save the script 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 strength/color slider) immediately if you have the blue light reduction page open when you run the command. For the slider to see the changes, you'll need to reopen the Settings app.

Solution 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.

Solution 3

Update for Windows 10 2004.

Created mainly to set the time Minutes-exact. 19:57 is three Minutes before "Tagesschau" in Germany.

How to use: Edit this commented registry file to your start and end times. Activate night light in the control panel since I don't know whether this reg file is enough. Import it. You can change the strength in the control panel, as long as you don't change the time setting it will stick to the values you set, showing it as "activated until 06:57" in your main display control panel.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\CloudStore\Store\DefaultAccount\Current\default$windows.data.bluelightreduction.settings\windows.data.bluelightreduction.settings]
; 4 bytes whatever, CloudStore Signature ?
"Data"=hex:43,42,01,00,\
; Might still be 64 Bit filetime, last time the setting was changed in the control panel
  0a,02,01,00,2a,06,c1,98,\
; 11 bytes whatever
  99,fb,05,2a,2b,0e,1f,43,42,01,00,\
; Acivated flag. It is is missing (i.e. ce,14, is here) is is off!
  02,01,\
; 3 bytes whatever
  ca,14,0e,\
; Starting Hour, 0x13 = 19
  13,\
; A constant
  2e,\
; Starting Minute, 0x39 = 57
  39,\
; 4 bytes whatever
  00,ca,1e,0e,\
; Ending Hour, 0x06 = 6 Uhr
  06,\
; A constant
  2e,\
; Ending Minute
  39,\
; 3 bytes constant
  00,cf,28,\
; Strength, here "33".
  9e,4a,\
; 10 bytes whatever (why so many trailing zeroes?)
  ca,32,00,ca,3c,00,00,00,00,00
Share:
14,496

Related videos on Youtube

David F. Severski
Author by

David F. Severski

Updated on September 18, 2022

Comments

  • David F. Severski
    David F. Severski over 1 year

    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!

    • magicandre1981
      magicandre1981 about 7 years
      use RegfromApp to trace it better. it generates the .reg file. maybe it can decode it
    • David F. Severski
      David F. Severski about 7 years
      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.
    • magicandre1981
      magicandre1981 about 7 years
      as I said, use Regfromapp, it generates .reg files for every change.
    • David F. Severski
      David F. Severski about 7 years
      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 github.com/jaapbrasser/SharedScripts/tree/master/Set-BlueLig‌​ht 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.
  • Gaboik1
    Gaboik1 over 6 years
    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
    Gaboik1 over 6 years
    I have also found, using this utility from NirSoft 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?
  • Ben N
    Ben N over 6 years
    @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.
  • Mgamerz
    Mgamerz over 5 years
    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.
  • metamorphosis
    metamorphosis about 5 years
    @Mgamerz Can confirm this is correct, and works in 1809. Have placed an edit on the answer.
  • Julien__
    Julien__ over 4 years
    As of today, last update, this doesn't work anymore. The registry key modified is \Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\‌​DefaultAccount\Curre‌​nt\default$windows.d‌​ata.bluelightreducti‌​on.settings\windows.‌​data.bluelightreduct‌​ion.settings\Data and sadly the binary format is not the same.
  • Julien__
    Julien__ over 4 years
    Why won't Windows provide a nice CLI interface to change settings ????
  • metamorphosis
    metamorphosis about 4 years
    Do you happen to have a script to enable-disable this by any chance?
  • hgrev
    hgrev about 4 years
    no. i wrote a small program in C.
  • metamorphosis
    metamorphosis about 4 years
    would still be useful (to me at least) if you could post a link. I work in C/C++
  • hgrev
    hgrev about 4 years
    do you want a code or exe file?
  • metamorphosis
    metamorphosis about 4 years
    Either if fine by me. :_)
  • Tor
    Tor about 4 years
    Found this answer after noticing that the registry values indeed do seem to increment and decrement for no apparent reason and gave up trying to make a scriptable method for altering it. But if you've figured it out, that's awesome. Do you make basic executables for enabling/disabling? If so, would you mind sharing, as I've been trying to create reusable shortcuts for this for a while!
  • hgrev
    hgrev about 4 years
    Here is the source code and executable: github.com/inamozov/DisplayTest
  • Tor
    Tor about 4 years
    Works great, thank you so much!
  • Ben N
    Ben N about 2 years
    @Julien__ Thanks for the tip. I finally got around to updating the script for version 21H2 (and probably working on some older versions).