使用 WUAPI 在 C# 中悄悄安装更新
我正在尝试创建一个可以静默处理更新的程序。我正在使用 wuapilib.dll,它附带了许多类(c#)。我对该程序的第一次修订如下(忽略拼写错误问题 - 它在另一台无法访问互联网的计算机上,所以我手动输入):
IUpdateSession mySess = new UpdateSession();
IUpdateSearcher mySear = mySess.CreateUpdateSearcher();
ISearchResult myRes = mySear.Search("Type='Software'");
IUpdateDownloader myDown = mySess.CreateUpdateDownloader();
IUpdateInstaller myInst = mySess.CreateUpdateInstaller();
myDown.Updates = myRes.Updates;
myDown.Download();
myInst.Updates = myRes.Updates;
myInst.Install();
忽略已经下载或安装更新的情况,我省略了上面的逻辑。我的问题是 IUpdateInstaller 不允许您强制进行静默安装 - 许多更新要求用户单击确认框。 IUpdateInstaller2 类确实如此(我从第二篇文章中得到了这个 这里),但是我一生都找不到获取 IUpdateInstaller2 对象的方法。似乎没有任何东西返回一个,并且微软的文档不包含任何示例代码。广泛的谷歌搜索没有返回任何有用的结果。
我想我已经非常接近了 - 功能就在那里,我只是无法完全访问它。
感谢您的帮助。
I'm trying to create a program that will handle updates silently. I am using the wuapilib.dll, which comes with a number of classes (c#). My first revision of the program was as follows (ignore typo problems - its on another computer without internet access so i'm typing it by hand):
IUpdateSession mySess = new UpdateSession();
IUpdateSearcher mySear = mySess.CreateUpdateSearcher();
ISearchResult myRes = mySear.Search("Type='Software'");
IUpdateDownloader myDown = mySess.CreateUpdateDownloader();
IUpdateInstaller myInst = mySess.CreateUpdateInstaller();
myDown.Updates = myRes.Updates;
myDown.Download();
myInst.Updates = myRes.Updates;
myInst.Install();
Ignore the case where an update is already downloaded or installed, I'm omitting the logic above. My problem is that IUpdateInstaller doesn't allow you to force a quiet install - a number of updates require that a user click a confirmation box. The IUpdateInstaller2 class does (I got that from the second post down here), but for the life of me I can't find a way to get an IUpdateInstaller2 object. Nothing seems to return one, and Microsoft's documentation doesn't contain any example code. Extensive googling returned nothing of use.
I think I'm really close - the functionality is there, I just can't quite access it.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我检查了这一点(或者更确切地说,我认为我做了 - 不太清楚如何让它工作),看起来 CreateUpdateInstaller 只返回一个 IUpdateInstaller,没有其他。
然而,我发现代码(在一个中文网站上,很有趣)直接将 IUpdateInstaller 转换为 IUpdateInstalelr2,这解决了我的问题。
感谢您的帮助
I checked that (or rather, I think i did - wasn't too clear on getting it to work), and it looks like the CreateUpdateInstaller only returns an IUpdateInstaller, nothing else.
However, I found code (on a chinese website, interestingly enough) that just directly cast the IUpdateInstaller to an IUpdateInstalelr2, which has solved my problems.
Thanks for the help
我在另一个问题中发布了我的应用程序,用于搜索、下载然后安装 Windows 更新。
请参阅:C# 和 WUAPI:BeginDownload 函数,
您可以轻松更改the:
然后
在事件完成后进行处理。例如,如果未找到更新,则关闭应用程序。我使用接口的异步属性,以便它可以执行异步所需的操作。
希望这有帮助。
I have posted in another Question my app to, search, download and then install Windows updates.
See: C# and WUAPI: BeginDownload function
you can easily change the:
then handle
after the events have done their thing. For example, if no Updates have been found, then close the app. I use the async properties of the interfaces so it can do what it needs to async.
Hope this helps.
我也找了好久才找到。
您只需要投射它即可
。根据 Microsoft 文档,还有版本 3 和版本 4 可用。但这一定是一个错误。版本 3 的功能在 IUpdateInstaller2 中也可用,而版本 4 的功能我从未在某处找到。
I also searched a long time for it.
You just need to cast it
According to Microsoft documentation there are also version 3 and 4 available. But this must be an error. The functions of version 3 are available also in IUpdateInstaller2 and the functions from version 4 I never found somewhere.