的.Net Windows更新查询

问题描述:

我很好奇,如果有一个.NET API,让我来识别哪些更新正在申请中的“Windows更新”,的.Net Windows更新查询

做不到这一点,是有一个Windows PowerShell命令,可以得到它?

Windows Update代理API可能是你在找什么:

http://msdn.microsoft.com/en-us/library/aa387287%28VS.85%29.aspx

这是一个COM接口(未.NET原生),但你可以消耗从您的应用程序。

这根本不是那么简单,但是你可以引用COM/WUAPI 2.0类型库,并且VS为你创建了一个托管包装,它被复制到WuApiLib.dll构建目录中。

请小心内存泄漏。

下面是一个VBScript,你可以用它来与

http://msdn.microsoft.com/en-us/library/aa387102(VS.85).aspx

您可以在PowerShell中很容易使用的COM对象安装更新。鉴于上述VBScript范例,您可以使用该对象在PS以及

PS C:\> $updateSession = new-object -com Microsoft.update.Session 
PS C:\> $updateSession | get-member 


    TypeName: System.__ComObject#{918efd1e-b5d8-4c90-8540-aeb9bdc56f9d} 

Name      MemberType Definition 
----      ---------- ---------- 
CreateUpdateDownloader  Method  IUpdateDownloader CreateUpdateDownloader() 
CreateUpdateInstaller  Method  IUpdateInstaller CreateUpdateInstaller() 
CreateUpdateSearcher  Method  IUpdateSearcher CreateUpdateSearcher() 
CreateUpdateServiceManager Method  IUpdateServiceManager2 CreateUpdateServiceManager() 
QueryHistory    Method  IUpdateHistoryEntryCollection QueryHistory (string, int, int) 
ClientApplicationID  Property string ClientApplicationID() {get} {set} 
ReadOnly     Property bool ReadOnly() {get} 
UserLocale     Property uint UserLocale() {get} {set} 
WebProxy     Property IWebProxy WebProxy() {get} {set} 


PS C:\> $searcher = $updateSession.CreateUpdateSearcher() 
PS C:\> $searcher | gm 


    TypeName: System.__ComObject#{04c6895d-eaf2-4034-97f3-311de9be413a} 

Name        MemberType Definition 
----        ---------- ---------- 
BeginSearch       Method  ISearchJob BeginSearch (string, IUnknown, Variant) 
EndSearch       Method  ISearchResult EndSearch (ISearchJob) 
EscapeString      Method  string EscapeString (string) 
GetTotalHistoryCount    Method  int GetTotalHistoryCount() 
QueryHistory      Method  IUpdateHistoryEntryCollection QueryHistory (int, int) 
Search        Method  ISearchResult Search (string) 
CanAutomaticallyUpgradeService  Property bool CanAutomaticallyUpgradeService() {get} {set} 
ClientApplicationID     Property string ClientApplicationID() {get} {set} 
IgnoreDownloadPriority    Property bool IgnoreDownloadPriority() {get} {set} 
IncludePotentiallySupersededUpdates Property bool IncludePotentiallySupersededUpdates() {get} {set} 
Online        Property bool Online() {get} {set} 
SearchScope       Property SearchScope SearchScope() {get} {set} 
ServerSelection      Property ServerSelection ServerSelection() {get} {set} 
ServiceID       Property string ServiceID() {get} {set} 


PS C:\> 

您可以继续使用Get-Member,找出所有不同的选择,基本上隐蔽说的VBScript到PowerShell和调整它做什么你需要它来做。

Andy