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 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.
use RegfromApp to trace it better. it generates the .reg file. maybe it can decode it
– magicandre1981 – 2017-04-16T16:48:20.870Thanks 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