This project started as an entry for NANY 2017, but because of
issues detailed in the thread, I didn't feel great releasing it.
As I already have the app ready to go, and just need to iron out said issues, I figured I could workshop it here with some others if anyone was willing. I'm also going to add a couple of other features around Windows Update and controlling it, so I figured I'd change the name.
To the primary issue- when I set the correct registry keys, the Windows UI for Active Hours does not register the change, though the registry keys are set correctly. Not only does it not register the change, it changes back to the default. I also made a change in the windows UI, and it does affect the registry keys that I expect, and saves the changes. I've tried it on 4 different machines, and the behavior is the same on all of them, so I don't think it's anything machine-based. They are all Windows 10 Home (1607/14393.576).
I figured that a picture is worth a thousand words.
First, the interface.
Basically, if you set the active hours for longer than 12 hours, it will find a 12 hour window that works based on your current time, and set the config file to be the whole length, and the registry keys to be that 12 hours. I was working on this very early in the morning, so when I set the span from 8AM to 11PM, it saved that to the application config (the bottom controls), and set windows to the computed span, i.e. 8AM to 8PM.
Then, the registry.
As you can see, the ActiveHoursStart key is set to 8, and the ActiveHoursEnd key is set to 20, as I expected.
Then I open the active hours dialog.
It was set to 10AM to 10PM before this, but as you can see, it reset the dialog to 8AM to 5PM.
The registry still shows the correct thing. But will it honor the registry? I don't know. I've set 3 of my computers to never reboot unless I manually reboot, so I only have one computer to test on. I have it currently set in the registry to active hours that do not overlap the 8-5 timespan, so I guess if I'm paying attention at the time, I'll see. But the kicker is that I have to be paying attention.
The code to make the change is quite simple:
public void SaveData()
{
if (this.DataHasChanged)
{
this._LoadingData = true;
try
{
using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\WindowsUpdate\UX\Settings", true))
{
var activeHours = this.GetActiveHours(Convert.ToDateTime(this.UserActiveHoursBegin).Hour,
Convert.ToDateTime(this.UserActiveHoursEnd).Hour);
registryKey.SetValue("ActiveHoursStart", activeHours.Item1);
registryKey.SetValue("ActiveHoursEnd", activeHours.Item2);
}
this.Config.AppSettings.Settings["ProgrammedActiveHoursBegin"].Value = Convert.ToDateTime(this.UserActiveHoursBegin).Hour.ToString();
this.Config.AppSettings.Settings["ProgrammedActiveHoursEnd"].Value = Convert.ToDateTime(this.UserActiveHoursEnd).Hour.ToString();
this.Config.Save(System.Configuration.ConfigurationSaveMode.Modified);
}
finally
{
this._LoadingData = false;
this.DataHasChanged = false;
}
this.LoadData();
}
}
Any thoughts?