How to know if windows update is waitng for installation [duplicate]

纵然是瞬间 提交于 2019-12-11 14:07:31

问题


Possible Duplicate:
Best way of detecting if Windows has Windows Updates ready to download/install?

I am using C# .net 3.5.

How can I know if there are updates ready to be installed in Windows Update?

On windows 8, when Windows Update is waiting to install updates, the sleep option is disabled.

Instead of the regular 3 options: 1. Sleep 2. Restart 3. Shutdown, there are only 2 options: 1. Restart and update 2. Shutdown and update. I need to identify this state and notify the user that the machine cannot move to sleep mode becuase updates are waiting to be installed.

Can I do it using WUAPILib?

Thanks


回答1:


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.



来源:https://stackoverflow.com/questions/12911218/how-to-know-if-windows-update-is-waitng-for-installation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!