Get automated notifications on #WindowsUpdate using C# and #WUApiLib
If you wanted to be notified as soon as a windows update is available on your server, but you don’t want it to be installed automatically, here is a script in C# that allows you to know when an update is ready.
It requires a COM library called WUApiLib which you can add via project > References
var updateSession = new UpdateSession();
var updateSearcher = updateSession.CreateUpdateSearcher();
updateSearcher.Online = false; //set to true if you want to search online
try
{
var searchResult = updateSearcher.Search(“IsInstalled=0 And IsHidden=0 And BrowseOnly=0”);
if (searchResult.Updates.Count > 0)
{
Console.WriteLine(“There are updates available for installation”);
foreach (IUpdate update in searchResult.Updates)
{
Console.WriteLine(update.Description);
foreach (string kbaid in update.KBArticleIDs)
{
Console.WriteLine(“http://support.microsoft.com/?kbid=” + kbaid);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message, “Error”);
}