topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 1:02 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Windows Update Controller  (Read 4785 times)

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Windows Update Controller
« on: January 02, 2017, 12:08 AM »
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:

Code: C# [Select]
  1. public void SaveData()
  2. {
  3.         if (this.DataHasChanged)
  4.         {
  5.                 this._LoadingData = true;
  6.  
  7.                 try
  8.                 {
  9.                         using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\WindowsUpdate\UX\Settings", true))
  10.                         {
  11.                                 var activeHours = this.GetActiveHours(Convert.ToDateTime(this.UserActiveHoursBegin).Hour,
  12.                                                             Convert.ToDateTime(this.UserActiveHoursEnd).Hour);
  13.                                 registryKey.SetValue("ActiveHoursStart", activeHours.Item1);
  14.                                 registryKey.SetValue("ActiveHoursEnd", activeHours.Item2);
  15.                         }
  16.                         this.Config.AppSettings.Settings["ProgrammedActiveHoursBegin"].Value = Convert.ToDateTime(this.UserActiveHoursBegin).Hour.ToString();
  17.                         this.Config.AppSettings.Settings["ProgrammedActiveHoursEnd"].Value = Convert.ToDateTime(this.UserActiveHoursEnd).Hour.ToString();
  18.                         this.Config.Save(System.Configuration.ConfigurationSaveMode.Modified);
  19.                 }
  20.                 finally
  21.                 {
  22.                         this._LoadingData = false;
  23.                         this.DataHasChanged = false;
  24.                 }
  25.                 this.LoadData();
  26.         }
  27. }

Any thoughts?

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Windows Update Controller
« Reply #1 on: January 03, 2017, 01:55 AM »
Interesting project.. It's always tricky to test programs that depend on wall clock time because you have to spend so much time waiting for things to trigger.
Even more so in this case because you're dealing with events that don't happen often.

A virtual machine is a great tool for this kind of problem, because you can mess with the time and date so easily, easily set up a virtual machine that needs updates, easily save snapshots so you can keep repeating a scenario, and not risk messing with your actual machine.

Have you tried using virtual machine for testing?

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Windows Update Controller
« Reply #2 on: January 03, 2017, 08:14 AM »
Have you tried using virtual machine for testing?

Nope.  Mostly because with Windows 10, I haven't really figured out how to get a licensed version into a VM since I don't have a version of windows 10 for it. :(

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Windows Update Controller
« Reply #3 on: January 03, 2017, 08:57 AM »
Nope.  Mostly because with Windows 10, I haven't really figured out how to get a licensed version into a VM since I don't have a version of windows 10 for it. :(

You can get a free, direct-from-Microsoft, time-limited (expires in April), Windows 10 VM here: https://developer.mi...ads/virtual-machines

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Windows Update Controller
« Reply #4 on: January 03, 2017, 11:57 AM »
Thanks!  I'll have to check that out!  :Thmbsup:

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Windows Update Controller
« Reply #5 on: January 03, 2017, 12:00 PM »
That's really odd that the MS gui does not seem to be reading the current registry values... Microsoft never makes things easy do they..  :mad:

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Windows Update Controller
« Reply #6 on: January 03, 2017, 03:37 PM »
Overall I really like Windows 10 (and it has some nice security and performance things under the hood!) - but Microsoft does seem hell-bent on enforcing a couple of things in ways I really don't like (telemetry, forced windows updates + boots).

I'll be kinda surprised if you get it to respect registry values!
- carpe noctem

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Windows Update Controller
« Reply #7 on: January 03, 2017, 04:22 PM »
Overall I really like Windows 10 (and it has some nice security and performance things under the hood!) - but Microsoft does seem hell-bent on enforcing a couple of things in ways I really don't like (telemetry, forced windows updates + boots).

I'll be kinda surprised if you get it to respect registry values!

The thing is... it was.  And it was working for a *lot* of people.  My program was even working.  So much so, that when I asked the question on the ten forums, they scoffed.  Then someone looked at the issue on a VM, and noticed that it no longer updated in the interface.  I think that they patched that particular back door to get around active hours out of existence, and did it quickly from th evidence that's left.  :(

Im still trying to work it oput, but it's honestly academic at this point, rather than me having any illusions this is going to turn out well.