Skip to content

Instantly share code, notes, and snippets.

@denim2x
Created June 13, 2018 08:10
Show Gist options
  • Save denim2x/5d733fa1d054c527f49537dc7919a06e to your computer and use it in GitHub Desktop.
Save denim2x/5d733fa1d054c527f49537dc7919a06e to your computer and use it in GitHub Desktop.
PowerShell cmdlet for setting Night Light on WIndows 10
Function Set-BlueLight {
[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
}
@denim2x
Copy link
Author

denim2x commented Jun 13, 2018

Similarly - Set-BlueLight

@nathanbabcock
Copy link

Here's one updated for Windows 11 22H2: https://github.com/nathanbabcock/nightlight-cli

@Enyium
Copy link

Enyium commented Jan 4, 2024

The most sophisticated tool to date to control Night Light: https://github.com/Enyium/sem-reg-rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment