如何根据KB编号批量隐藏Windows 7更新?

问题描述 投票:1回答:2

Hy,我有兴趣找到一种方法(也许是vbs脚本?)来隐藏几个(超过10个,无论如何)windows 7更新,所以它们永远不会被安装。我认为最好的方法是,如果我可以解析一个.txt文件,其中列出了每个KB编号(每个都在新行上)。但是,当然,如果它使代码更简单,那么脚本内部硬编码的数组也可以正常工作。唯一的要求是按KB编号而不是说明。

问题是我不知道我应该怎么做,因此我向你们寻求帮助。

非常感谢你!

batch-processing windows-update
2个回答
3
投票

您绝对可以使用VBS脚本执行此操作。其他一些StackExchange站点已经回答了类似的问题(参见How to disable the “Get Windows 10” icon shown in the notification area (tray)?Block specific Windows update hotfix

与您的问题相关的部分将在下面复制。原始问题值得一读,并且还有其他注释可能也会有所帮助。

这些是专门为处理GWX更新而编写的,但您可以使用任何KB编号。

“BlockWindows10.bat”:

ECHO OFF
REM --- remember to invoke from ELEVATED command prompt!
REM --- or start the batch with context menu "run as admin".
SETLOCAL

REM --- (as of 2015-09-07):
REM  KB3035583 - GWX Update installs Get Windows 10 app in Windows 8.1 and Windows 7 SP1
REM  KB3021917 - Update to Windows 7 SP1 for performance improvements
REM  KB3012973 - Upgrade to Windows 10 Pro

REM --- no longer blocking:
REM  KB2952664 - Compatibility update for upgrading Windows 7
REM  KB2976978 - Compatibility update for Windows 8.1 and Windows 8
REM  KB3022345 - Telemetry [Replaced by KB3068708]
REM  KB3068708 - Update for customer experience and diagnostic telemetry

REM --- uninstall updates
echo uninstalling updates ...
start "title" /b /wait wusa.exe /kb:3021917 /uninstall /quiet /norestart
echo  - next
start "title" /b /wait wusa.exe /kb:3035583 /uninstall /quiet /norestart
echo  - done.
timeout 10

REM --- hide updates
echo hiding updates ...
start "title" /b /wait cscript.exe "%~dp0HideWindowsUpdates.vbs" 3021917 3035583 3012973
echo  - done.

echo ... COMPLETED (please remember to REBOOT windows, now)
pause
REM --- EOF

“HideWindowsUpdates.vbs”(Kudo https://serverfault.com/a/341318):

'// Inspired by Colin Bowern: https://serverfault.com/a/341318
If Wscript.Arguments.Count < 1 Then
    WScript.Echo "Syntax: HideWindowsUpdates.vbs [KB1] [KB2] ..." & vbCRLF & _
        " - Example1: HideWindowsUpdates.vbs 3035583" & vbCRLF & _
        " - Example2: HideWindowsUpdates.vbs 3035583 3012973"
    WScript.Quit 1
End If

Dim objArgs
Set objArgs = Wscript.Arguments
Dim updateSession, updateSearcher
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateUpdateSearcher()

Wscript.Stdout.Write "Searching for pending updates..." 
Dim searchResult
Set searchResult = updateSearcher.Search("IsInstalled=0")

Dim update, kbArticleId, index, index2
WScript.Echo CStr(searchResult.Updates.Count) & " found."
For index = 0 To searchResult.Updates.Count - 1
    Set update = searchResult.Updates.Item(index)
    For index2 = 0 To update.KBArticleIDs.Count - 1
        kbArticleId = update.KBArticleIDs(index2)

        For Each hotfixId in objArgs
            If kbArticleId = hotfixId Then
                If update.IsHidden = False Then
                    WScript.Echo "Hiding update: " & update.Title
                    update.IsHidden = True
                Else
                    WScript.Echo "Already hiddn: " & update.Title
                End If          
            End If
        Next

    Next
Next
'// EOF

0
投票

感谢您的帮助。与此同时,我能够整理我的剧本。不完美,它可能有错误,但我在我的Windows 7 Pro x64上运行它,它的行为符合预期。

对于任何有兴趣的人,请随时在这里查看:https://github.com/dereius/WindowsUpdateHider

© www.soinside.com 2019 - 2024. All rights reserved.