2

I have an application that periodically checks and patches windows updates. However, it can cause conflicts when windows update is already running (either downloading KBs or installing them). I want to know how do you programmatically check if windows update is already running?

  • In Windows 10 it is always running. I can't think of a legit use case for "patching" Windows system files, but if there is one maybe you could get file system updates instead and "patch" files when they change. – Dave S Jan 24 '18 at 19:18
  • Perhaps have a look at this question: https://stackoverflow.com/questions/1591342/c-how-to-determine-if-a-windows-process-is-running/1591370. – DeiDei Jan 24 '18 at 19:24
  • 1
    @DaveS Is not always running. It starts either manually or by trigger and then exits. As for question itself it might be worth to check whether `wuauserv` service is running. – user7860670 Jan 24 '18 at 19:39
  • @VTT, thanks for the suggestion. I tried to manually run windows update on Windows 10 and monitor wuauserv's status on task manager and the result is not very accurate. Even after I finished checking for updates, the service still showed the status "Running". – Joanna Zhou Jan 24 '18 at 21:10

1 Answers1

-1

We could use the IUpdateInstaller::get_IsBusy method in the wuapi.h header to detect if Windows update is installing patches. I used it from C#, and confirmed that the sample code below detects if Windows Update is installing patches.

var session = new UpdateSession();
var installer = session.CreateUpdateInstaller();

while (true)
{
    Console.WriteLine(DateTime.Now.ToString());
    Console.WriteLine($"installer.IsBusy={installer.IsBusy}");
    Thread.Sleep(TimeSpan.FromSeconds(1));
}

"WUAPI 2.0 Type Library" needs to be added as a reference. The code above could be re-written with C++.

I don'know know how to detect if Windows Update is downloading patches, though...

nodchip
  • 361
  • 1
  • 3
  • 10