Last active
March 6, 2021 15:58
-
-
Save byt3bl33d3r/d29f428085e2f841f43bd5fca8436d2a to your computer and use it in GitHub Desktop.
Uses the Windows Update Agent API (WUA API) COM Object to check if there are definition updates available for Windows Defender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add a reference to "WUAPI 2.0 Type Library" in Visual Studio | |
// References: | |
// - https://github.com/xonv/nagios-net-client/blob/0920114874ecc85fc7ab3a4426e547c9dc63a44a/NscaWinUpdateModule/WindowsUpdate.cs | |
// - https://docs.microsoft.com/en-us/windows/win32/wua_sdk/portal-client | |
using System; | |
using WUApiLib; | |
namespace WinUpdateTest | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
var uSess = new UpdateSession(); | |
var uSearcher = uSess.CreateUpdateSearcher(); | |
var searchResult = uSearcher.Search("IsInstalled=0 and Type='Software'"); | |
if (searchResult.Updates.Count > 0) | |
{ | |
foreach (IUpdate x in searchResult.Updates) | |
{ | |
Console.WriteLine(x.Title); | |
foreach (ICategory cat in x.Categories) | |
{ | |
switch (cat.Type) | |
{ | |
case "UpdateClassification": | |
if (cat.Name == "Definition Updates") | |
Console.WriteLine("Windows Defender updates are available!"); | |
break; | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment