How to know if there is a Windows update to install

Possible Duplicate:
What is the best way to determine if Windows is ready to update Windows?

I am using C # .net 3.5.

How do I know if there are any ready-to-update updates in Windows Update?

On Windows 8, when Windows Update is waiting for updates to be installed, the sleep option is disabled.

Instead of the usual 3 options: 1. Sleep 2. Restart 3. Shutdown, there are only 2 options: 1. Restart and update 2. Shutdown and update. I need to detect this state and notify the user that the machine cannot hibernate because updates are waiting to be installed.

Can I do this with WUAPILib?

thank

0


source to share


1 answer


You can use WUApiLib (Com lib) for this:

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");
    if (searchResult.Updates.Count > 0)
    {
        MessageBox.Show("There are updates available for installation");
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message,"Error");
}

      



Click here if you want to know more.

+3


source







All Articles