Click here to Skip to main content
16,022,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am constructing a service to deal with Windows Updates remotely on some servers. That is not the issue. The issue I am encountering is getting Windows to finalize updates during the reboot. It's like there is a flag somewhere that needs to be set telling Windows that 1) the system needs to be rebooted for update install and 2) to actually install the pending updates during reboot. Surprisingly enough, this is not exactly a trivial issue.

Does anyone have any hints on how to set Windows to recognize that it needs to deal with finalizing updated during a reboot?

What I have tried:

I have tried the following with no joy...
1) executing "shutdown /r /f /t 0" and versions thereof - the service runs with admin privileges so that shouldn't be the issue.
2) calling api exitWindowsEx both with and without privilege setting
3) Just rebooting Windows from the GUI

Yes, these all indeed reboot the computer in question. None of them go through the update finalize process.
Posted
Updated 2-Jul-23 2:33am
Comments
[no name] 25-Jun-23 14:43pm    
Try adding and removing a registry key under program control.

https://foxlearn.com/articles/how-to-make-an-application-auto-run-on-windows-startup-in-csharp-279.html#:~:text=1%20Step%201%20%3A%20Click%20New%20Project%2C%20then,Add%20code%20to%20handle%20your%20form%20as%20below

If your service takes care of updating Windows, I suggest, to set the "CanShutdown" flag (e.g. in the "InitializeComponent()" routine set: "Me.CanShutdown = True"), then add to the main class the "Protected Overrides OnShutdown()" routine and put the working code here.

Alternatively, you can try the following trick. Write a .cmd file (e.g. "stopsystem.cmd"), include the following in your shell script:

::It runs before shutdown.
@echo off
net start wuauserv

Place the cmd script in the directory:
%SystemRoot%\System32\GroupPolicy\Machine\Scripts\Shudown

Then open GPEdit, On the computer branch go to "Windows Settings" --> "Script" --> "Stop", here you select the cmd file.
Run from prompt "GPUpdate /force"

Then try restarting the machine.
It should work.
 
Share this answer
 
I found the actual solution to this problem. Just leaving this here for others to find:

The actual answer is to call IUpdateInstaller4::Commit after all your updates have been installed.

Note that this does not actually turn on the "reboot needed" indicators within Windows (the red dot icon in the system tray, the "update and reboot" options in the power submenu from the start menu, etc...). It does however work with making the update actually install at next boot. Tested with the latest Insider Preview.

IUpdateInstaller4::Commit (wuapi.h) - Win32 apps | Microsoft Learn[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900