That's a lot of work to hide the window... and there is a much easier way. All you need to do is in your scheduled task, select "Run whether user is logged in or not", the select an account to run as and enter the password. SHAZAAM!!! All fixed.
Here are the steps to put it all together. Incredibly easy. Promise!
- Open Notepad and enter these four lines of text...
for /f "tokens=*" %%a in ('powershell "(Get-Date).Hour"') do set startHour=%%a
set /a "endHour=(%starthour%+18)%%24"
reg add HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings /v ActiveHoursStart /t REG_DWORD /d %startHour% /f
reg add HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings /v ActiveHoursEnd /t REG_DWORD /d %endHour% /f
- Save the file as "Roll_Active_Hours.cmd". Don't use .BAT. It's ancient DOS. .CMD is slightly more modern, the NT era.
- Open Task Scheduler and create a new task. Select "Run with highest privileges" and "Run whether user is logged in or not" and "Configure For: Windows 10", since there is no Windows 11 option within Windows 11.
- In Triggers, create a single trigger. Choose "One time" and choose today's date and 12:00:00 PM. Then select Repeat task every: 12 hours. If there is no option in the drop down for 12 hours... just type it in. I check "Stop task if runs longer than: " and select 1 minute. If it takes longer than that, something is wrong. And of course, check the Enabled box to activate the trigger.
- In the Actions tab, select "Start a program" and then use the Browse... button to locate the "Roll_Active_Hours.cmd" script from steps 1 and 2.
- Everything on the Conditions tab should be unselected. In the Settings tab, check "Allow task to be run on demand" and "Run task as soon as possible after a scheduled start is missed" and "If the running ask does not end when requests, force it to stop".
That's it. No windows flashing when the task runs. Only runs twice per day. You can run it manually if you like. And Windows 11 will never restart on its own.