Skip to content

Instantly share code, notes, and snippets.

@byt3bl33d3r
Last active March 6, 2021 15:58
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save byt3bl33d3r/d29f428085e2f841f43bd5fca8436d2a to your computer and use it in GitHub Desktop.
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
// 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