使用C#与Windows交互更新 [英] Use C# to interact with Windows Update

查看:183
本文介绍了使用C#与Windows交互更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有写,可以与Windows更新界面,并用它来选择安装某些更新C#程序的API?

Is there any API for writing a C# program that could interface with Windows update, and use it to selectively install certain updates?

我沿着批准的更新的中央存储库存储列表的思路思考的地方。然后,客户端应用程序(必须安装一次)将与Windows更新界面,以确定哪些更新可用,然后安装在核准名单上的人。这样,更新仍自动从客户端的角度看应用,但我可以选择正在应用哪些更新。

I'm thinking somewhere along the lines of storing a list in a central repository of approved updates. Then the client side applications (which would have to be installed once) would interface with Windows Update to determine what updates are available, then install the ones that are on the approved list. That way the updates are still applied automatically from a client-side perspective, but I can select which updates are being applied.

这是不是由我的方式在公司的角色,我真的只是想知道是否有适用于Windows更新的API,以及如何使用它。

This is not my role in the company by the way, I was really just wondering if there is an API for windows update and how to use it.

推荐答案

添加引用WUApiLib到C#项目。

Add a Reference to WUApiLib to your C# project.

using WUApiLib;
protected override void OnLoad(EventArgs e){
    base.OnLoad(e);
    UpdateSession uSession = new UpdateSession();
    IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
    uSearcher.Online = false;
    try {
        ISearchResult sResult = uSearcher.Search("IsInstalled=1 And IsHidden=0");
        textBox1.Text = "Found " + sResult.Updates.Count + " updates" + Environment.NewLine;
        foreach (IUpdate update in sResult.Updates) {
                textBox1.AppendText(update.Title + Environment.NewLine);
        }
    }
    catch (Exception ex) {
        Console.WriteLine("Something went wrong: " + ex.Message);
    }
}

鉴于你有一个文本框的表单这会给你当前已安装的更新列表。见<一href=\"http://msdn.microsoft.com/en-us/library/aa387102(VS.85).aspx\">http://msdn.microsoft.com/en-us/library/aa387102(VS.85).aspx更多的文档。

这将,但是,不会让你查找不通过Windows Update分发KB修补程序。

This will, however, not allow you to find KB hotfixes which are not distributed via Windows Update.

这篇关于使用C#与Windows交互更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆