如何判斷已安裝的 .NET Framework 安全性更新和修補程式How to determine which .NET Framework security updates and hotfixes are installed

本文說明如何找出安裝在電腦上的 .NET Framework 安全性更新與 Hotfix。This article shows you how to find out which .NET Framework security updates and hotfixes are installed on a computer.

注意

本文中展示的所有技術,皆需要使用具備系統管理權限的帳戶。All the techniques shown in this article require an account with administrative privileges.

使用登錄編輯程式Use Registry Editor

已為電腦上安裝之各版 .NET Framework 所安裝之安全性更新與 Hotfix,都列於 Windows 登錄中。The installed security updates and hotfixes for each version of the .NET Framework installed on a computer are listed in the Windows registry. 您可使用登錄編輯程式 (regedit.exe) 程式,檢視此資訊。You can use the Registry Editor (regedit.exe) program to view this information.

  1. 開啟 regedit.exe 程式。Open the program regedit.exe. 在 Windows 8 和更新版本中,以滑鼠按右鍵![[windows 金鑰標誌] 的 開始螢幕擷取畫面],然後選取 [執行]。In Windows 8 and later versions, right-click Start Screenshot of the Windows key logo., then select Run. 在 [開啟]方塊中,輸入 regedit,然後選取 [確定]。In the Open box, enter regedit and select OK.

  2. 在 [登錄編輯程式] 中,開啟下列子機碼:In the Registry Editor, open the following subkey:

    HKEY_LOCAL_MACHINE \SOFTWARE\Wow6432Node\Microsoft\UpdatesHKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Updates

    已安裝的更新會列於子機碼下,這些子機碼可識別套用更新的 .NET Framework 版本。The installed updates are listed under subkeys that identify the .NET Framework version they apply to. 每個更新都是透過知識庫 (KB) 號碼加以識別。Each update is identified by a Knowledge Base (KB) number.

在登錄編輯程式中,.NET Framework 版本和每一版已安裝的更新會儲存在不同的子機碼中。In the Registry Editor, the .NET Framework versions and installed updates for each version are stored in different subkeys. 如需偵測已安裝之版本號碼的相關資訊,請參閱如何:判斷安裝的 .NET Framework 版本For information about detecting the installed version numbers, see How to: Determine which .NET Framework versions are installed.

使用程式碼查詢登錄Query the registry using code

下列範例以程式設計方式判斷電腦上安裝的 .NET Framework 安全性更新與 Hotfix:The following example programmatically determines the .NET Framework security updates and hotfixes that are installed on a computer:

using System;
using Microsoft.Win32;

public class GetUpdateHistory
{
    public static void Main()
    {
        using (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\Updates"))
        {
            foreach (string baseKeyName in baseKey.GetSubKeyNames())
            {
                if (baseKeyName.Contains(".NET Framework"))
                {
                    using (RegistryKey updateKey = baseKey.OpenSubKey(baseKeyName))
                    {
                        Console.WriteLine(baseKeyName);
                        foreach (string kbKeyName in updateKey.GetSubKeyNames())
                        {
                            using (RegistryKey kbKey = updateKey.OpenSubKey(kbKeyName))
                            {
                                Console.WriteLine("  " + kbKeyName);
                            }
                        }
                    }
                }
            }
        }
    }
}

Imports Microsoft.Win32

Public Class GetUpdateHistory
    Public Shared Sub Main()
        Using baseKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\Microsoft\Updates")
            For Each baseKeyName As String In baseKey.GetSubKeyNames()
                If baseKeyName.Contains(".NET Framework") Then
                    Using updateKey As RegistryKey = baseKey.OpenSubKey(baseKeyName)
                        Console.WriteLine(baseKeyName)
                        For Each kbKeyName As String In updateKey.GetSubKeyNames()
                            Using kbKey As RegistryKey = updateKey.OpenSubKey(kbKeyName)
                                Console.WriteLine("  " & kbKeyName)
                            End Using
                        Next
                    End Using
                End If
            Next
        End Using
    End Sub
End Class

該範例會產生類似如下的輸出:The example produces an output that's similar to the following one:

Microsoft .NET Framework 4 Client Profile
  KB2468871
  KB2468871v2
  KB2478063
  KB2533523
  KB2544514
  KB2600211
  KB2600217
Microsoft .NET Framework 4 Extended
  KB2468871
  KB2468871v2
  KB2478063
  KB2533523
  KB2544514
  KB2600211
  KB2600217

使用 PowerShell 查詢登錄Use PowerShell to query the registry

下列範例示範如何使用 PowerShell 判斷電腦上安裝的 .NET Framework 安全性更新與 Hotfix:The following example shows how to determine the .NET Framework security updates and hotfixes that are installed on a computer using PowerShell:

$DotNetVersions = Get-ChildItem HKLM:\SOFTWARE\WOW6432Node\Microsoft\Updates | Where-Object {$_.name -like
 "*.NET Framework*"}

ForEach($Version in $DotNetVersions){
    
   $Updates = Get-ChildItem $Version.PSPath
    $Version.PSChildName
    ForEach ($Update in $Updates){
       $Update.PSChildName
       }
}

該範例會產生類似如下的輸出:The example produces an output that's similar to the following one:

Microsoft .NET Framework 4 Client Profile
KB2468871
KB2468871v2
KB2478063
KB2533523
KB2544514
KB2600211
KB2600217
Microsoft .NET Framework 4 Extended
KB2468871
KB2468871v2
KB2478063
KB2533523
KB2544514
KB2600211
KB2600217

請參閱See also