Skip to content

Instantly share code, notes, and snippets.

@Nevember
Last active October 24, 2022 09:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nevember/fb95334cac11c6a3b8d9742c8f2b89b7 to your computer and use it in GitHub Desktop.
Save Nevember/fb95334cac11c6a3b8d9742c8f2b89b7 to your computer and use it in GitHub Desktop.
Enable "Dark Mode" at 6:30pm daily using this Windows Task Scheduler XML file
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2022-10-23T19:30:00.0000000</Date>
<Author>SCI\SpiralChaotic</Author>
<URI>\SCI\DarkModeEnable</URI>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2022-10-23T18:30:00</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>%ComputerName%\%Username%</UserId>
<LogonType>S4U</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>true</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
<Priority>7</Priority>
<RestartOnFailure>
<Interval>PT1M</Interval>
<Count>3</Count>
</RestartOnFailure>
</Settings>
<Actions Context="Author">
<Exec>
<Command>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe</Command>
<Arguments>-NoProfile -NonInteractive -ExecutionPolicy Unrestricted $RegPath = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize'; New-ItemProperty -Path $RegPath -Name SystemUsesLightTheme -Value 0 -Type Dword -Force; New-ItemProperty -Path $RegPath -Name AppsUseLightTheme -Value 0 -Type Dword -Force</Arguments>
</Exec>
</Actions>
</Task>
@Nevember
Copy link
Author

Nevember commented Oct 24, 2022

Almost 100% based on this Windows Central article.

I changed powershell.exe's command switches to include -NoProfile, -NonInteractive, and -ExecutionPolicy Unrestricted.
For semantic purposes, I slightly changed the PowerShell code so that it reads as follows:

$RegPath = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize'
New-ItemProperty -Path $RegPath -Name SystemUsesLightTheme -Value 0 -Type Dword -Force
New-ItemProperty -Path $RegPath -Name AppsUseLightTheme -Value 0 -Type Dword -Force

I also made some adjustments to the task's "Conditions" and "Settings" tabs.

@Nevember
Copy link
Author

Nevember commented Oct 24, 2022

Usage via Task Scheduler:

  1. Save the file from this gist to your computer
  2. Open Task Scheduler (taskschd.msc)
  3. Choose a Task Scheduler Library from the pane on the left
  4. Right-click any whitespace in the main pain, then click "Import Task..."
  5. Navigate to the location where you saved the .xml file, select it, then click "Open"
  6. A "Create Task" dialog will appear, pre-populated with the values from the .xml file
  7. Click the "Change User or Group..." button
  8. Enter your Windows username, then press enter (or click "OK")
  9. Click "OK" to close the dialog; the task has been imported

To test the task, ensure your computer isn't already using this mode, then right-click the task and click "Run." The change should occur almost immediately. Return to Task Schedule and refresh the window by pressing F5. The "Last Run Result" column should state, "The operation completed successfully. (0x0)."

To change the schedule, double click the task to edit it, choose the "Triggers" tab, then click "Edit..." Follow the prompts to make your desired changes.

Bonus note:
If you'd like to skip steps 7 and 8 above, simply edit line 19 in the XML file using your favorite text editor, replacing "%ComputerName%\%Username%" with your username, e.g. "Nevember."
(In most cases you don't need to include the computer name or a domain name.)

@Nevember
Copy link
Author

Also check out this gist's partner, Light_Mode_Enable.xml, which I recommend using in conjunction with this one.

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