如何发现 Windows 更新是可选、推荐还是重要

Woo*_*g79 5 vb.net windows windows-update

我目前正在编写一种自动化程序,其中包括搜索 Windows 更新。它可以很好地搜索和检索更新,但我无法深入了解更新的优先级。我想要类似的输出:

总更新:25 重要:12 可选:13

.IsMandatory 字段仅在更新专门针对 WUA 本身时使用,因此重要的更新不必用 .IsMandatory 标记。

搜索用水户协会的代码片段如下:

Dim updateSession  ' Object to hold our MS Update Session
Dim updateSearcher ' Object to perform our MS Win Update Search
Dim results        ' Object to hold our MS Win Update Search Results
Dim stopWatch As New Stopwatch()
stopWatch.Start()

outputWriter.WriteLine("----WINDOWS UPDATES-----@ " & Now, False)
outputWriter.WriteLine("  -We are beginning our update search. Please note, this may take a few minutes." & _
                       "  On Windows Server 2003 this may take 800 years.", False)

' We cannot guarantee the update check will succeed, so use a try catch in case of error.
Try
    updateSession = CreateObject("Microsoft.Update.Session")
    updateSearcher = updateSession.CreateUpdateSearcher()
    results = updateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
Catch ex As Exception
    outputWriter.WriteLine("  ERROR: Something went wrong in our update search. Details below...", False)
    outputWriter.WriteLine("  Error Msg: " & ex.Message, False)
    Return 1
 End Try

Dim imp_updates = 0
Dim opt_updates = 0
For i = 0 To results.Updates.Count - 1
    Dim update = results.Updates.Item(i)
    If update.IsMandatory = False Then 
        opt_updates = opt_updates + 1
    Else
        imp_updates = imp_updates + 1
    End If
 Next

 outputWriter.WriteLine("Important Updates: " & imp_updates, True)
 outputWriter.WriteLine("Optional Updates:  " & opt_updates, True)
Run Code Online (Sandbox Code Playgroud)

小智 1

您应该能够检查更新的MsrcSeverity :

    Select Case update.MsrcSeverity
        Case "Important"
        Case "Critical"
        Case "Moderate"
        Case "Low"
        Case "Unspecified"
    End Select
Run Code Online (Sandbox Code Playgroud)