3

「Windows Update」で保留中の更新プログラムを特定できる .Net API があるかどうか、興味がありました。

それに失敗した場合、それを取得できるWindows PowerShellコマンドはありますか?

4

3 に答える 3

4

これは、更新プログラムをインストールするために使用できる 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 に変換し、それを微調整して必要なことを行うことができます。

アンディ

于 2008-12-12T02:36:02.523 に答える
3

Windows Update Agent API は、探しているものである可能性があります。

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

これは COM インターフェイス (.NET ネイティブではない) ですが、アプリケーションから使用できます。

于 2008-12-10T16:40:44.957 に答える
0

これはまったく簡単なことではありませんが、COM/WUAPI 2.0 タイプ ライブラリを参照するだけで、VS によってマネージ ラッパーが作成され、ビルド ディレクトリに WuApiLib.dll としてコピーされます。

メモリリークに注意してください。

于 2008-12-10T16:50:04.580 に答える