Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check from .NET if Windows Update is enabled

Is there any way to check from .NET if windows update is enabled?

I want to prompt the users every time they log into my app that their computer might be at risk and give them a link to windows update website (or windows update application from control panel).

Preferably it should work on XP, Vista and Windows 7. Maybe there is a registry key or even better an API?

like image 676
Ovi Avatar asked Mar 25 '09 15:03

Ovi


People also ask

Is .NET part of Windows Update?

NET Framework 4.8 is included with: Windows 10 May 2021 Update. Windows 10 October 2020 Update.

Is .NET automatically updated?

We're excited to announce that starting April 2022, we will be making monthly updates for modern . NET (. NET Core) available for server operating systems via Microsoft Update (MU) on an opt-in basis. If you do not want to have your servers updated automatically for you no action is required.


2 Answers

First add a reference to WUApiLib "C:\windows\system32\Wuapi.dll"

Then you can use this code snippet.

WUApiLib.AutomaticUpdatesClass auc = new WUApiLib.AutomaticUpdatesClass();
bool active = auc.ServiceEnabled;

MSDN: "The ServiceEnabled property indicates whether all the components that Automatic Updates requires are available."

The Setting auc.Settings.NotificationLevel contains the information about the current mode. http://msdn.microsoft.com/en-us/library/aa385806(VS.85).aspx

like image 121
Michael Piendl Avatar answered Oct 13 '22 16:10

Michael Piendl


Of course it is your choice to do that but getting prompted every few minutes that WindowsUpdate was switched off was by far the worst usability issue in XP.

You don't want to irritate your users. You should love them. And definitely not intrude in their private affairs like checking out if WU is off because honestly it's no business of yours.

like image 45
User Avatar answered Oct 13 '22 15:10

User