.Net Windows Update查询

时间:2008-12-10 16:35:47

标签: .net powershell windows-update

我很好奇是否有.Net API可以让我确定哪些更新待处理“Windows Update”

失败了,是否有可以获得它的Windows powershell命令?

3 个答案:

答案 0 :(得分:3)

您可能正在寻找Windows Update Agent API:

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

它是一个COM接口(不是.NET本机),但您可以从应用程序中使用它。

答案 1 :(得分:3)

以下是可用于使用

安装更新的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并调整它以做任何你需要做的事情。

安迪

答案 2 :(得分:0)

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

小心内存泄漏。