Home > Uncategorized > Get automated notifications on #WindowsUpdate using C# and #WUApiLib

Get automated notifications on #WindowsUpdate using C# and #WUApiLib

Windows-Update-en-Windows-7

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”);
}

 

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: