Kiểm Tra Máy Đã Cài Net Framework Chưa

  -  

In this article

Users can install and run multiple versions of .NET Framework on their computers. When you develop or deploy your app, you might need khổng lồ know which .NET Framework versions are installed on the user"s computer. The registry contains a menu of the versions of .NET Framework installed on the computer.

Bạn đang xem: Kiểm tra máy đã cài net framework chưa


Note

This article is specific to .NET Framework. Khổng lồ determine which .NET Core and .NET 5+ SDKs & runtimes are installed, see How to check that .NET is already installed.


.NET Framework consists of two main components, which are versioned separately:

A mix of assemblies, which are collections of types và resources that provide the functionality for your apps. .NET Framework and the assemblies cốt truyện the same version number. For example, .NET Framework versions include 4.5, 4.6.1, và 4.7.2.

Community-maintained tools are available khổng lồ help detect which .NET Framework versions are installed:

For information about detecting the installed updates for each version of .NET Framework, see How to: Determine which .NET Framework updates are installed.

Determine which .NET implementation and version an phầm mềm is running on

You can use the RuntimeInformation.FrameworkDescription property to query for which .NET implementation và version your phầm mềm is running on. If the phầm mềm is running on .NET Framework, the đầu ra will be similar to:

.NET Framework 4.8.4250.0By comparison, if the phầm mềm is running on .NET bộ vi xử lý core or .NET 5+, the output đầu ra will be similar to:

.NET chip core 3.1.9.NET 5.0.0

Detect .NET Framework 4.5 & later versions

The version of .NET Framework (4.5 và later) installed on a machine is listed in the registry at HKEY_LOCAL_MACHINESOFTWAREhostingvietnam.vnNET Framework SetupNDPv4Full. If the Full subkey is missing, then .NET Framework 4.5 or above isn"t installed.


The Release REG_DWORD value in the registry represents the version of .NET Framework installed.

.NET Framework versionValue of Release
.NET Framework 4.5All Windows operating systems: 378389
.NET Framework 4.5.1On Windows 8.1 và Windows hệ thống 2012 R2: 378675On all other Windows operating systems: 378758
.NET Framework 4.5.2All Windows operating systems: 379893
.NET Framework 4.6On Windows 10: 393295On all other Windows operating systems: 393297
.NET Framework 4.6.1On Windows 10 November Update systems: 394254On all other Windows operating systems (including Windows 10): 394271
.NET Framework 4.6.2On Windows 10 Anniversary Update và Windows server 2016: 394802On all other Windows operating systems (including other Windows 10 operating systems): 394806
.NET Framework 4.7On Windows 10 Creators Update: 460798On all other Windows operating systems (including other Windows 10 operating systems): 460805
.NET Framework 4.7.1On Windows 10 Fall Creators Update and Windows Server, version 1709: 461308On all other Windows operating systems (including other Windows 10 operating systems): 461310
.NET Framework 4.7.2On Windows 10 April 2018 Update and Windows Server, version 1803: 461808On all Windows operating systems other than Windows 10 April 2018 Update and Windows Server, version 1803: 461814
.NET Framework 4.8On Windows 10 May 2019 Update & Windows 10 November 2019 Update: 528040On Windows 10 May 2020 Update & Windows 10 October 2020 Update và Windows 10 May 2021 Update: 528372On Windows 11 và Windows vps 2022: 528449On all other Windows operating systems (including other Windows 10 operating systems): 528049

Minimum version

To determine whether a minimum version of .NET Framework is present, kiểm tra for a Release REG_DWORD value that"s greater than or equal to lớn the corresponding value listed in the following table. For example, if your application runs under .NET Framework 4.8 or a later version, demo for a Release REG_DWORD value that"s greater than or equal to 528040.

.NET Framework versionMinimum value
.NET Framework 4.5378389
.NET Framework 4.5.1378675
.NET Framework 4.5.2379893
.NET Framework 4.6393295
.NET Framework 4.6.1394254
.NET Framework 4.6.2394802
.NET Framework 4.7460798
.NET Framework 4.7.1461308
.NET Framework 4.7.2461808
.NET Framework 4.8528040

Use Registry Editor

From the Start menu, choose Run, enter regedit, & then select OK.

(You must have administrative credentials to run regedit.)

In the Registry Editor, mở cửa the following subkey: HKEY_LOCAL_MACHINESOFTWAREhostingvietnam.vnNET Framework SetupNDPv4Full. If the Full subkey isn"t present, then you don"t have .NET Framework 4.5 or later installed.

Check for a REG_DWORD entry named Release. If it exists, then you have .NET Framework 4.5 or later installed. Its value corresponds lớn a particular version of .NET Framework. In the following figure, for example, the value of the Release entry is 528040, which is the release key for .NET Framework 4.8.

*

Use PowerShell to check for a minimum version

Use PowerShell commands to check the value of the Release entry of the HKEY_LOCAL_MACHINESOFTWAREhostingvietnam.vnNET Framework SetupNDPv4Full subkey.

The following examples kiểm tra the value of the Release entry to lớn determine whether .NET Framework 4.6.2 or later is installed. This code returns True if it"s installed & False otherwise.

Xem thêm: Cách Sửa Lỗi Không Vào Được Mạng Win 7 Win 10, Lỗi Laptop Không Bắt Được Wifi Trong Win 7

(Get-ItemProperty "HKLM:SOFTWAREhostingvietnam.vnNET Framework SetupNDPv4Full").Release -ge 394802

Query the registry using code

The following example checks the value of the Release entry in the registry to lớn find the versions of .NET Framework 4.5-4.8 that are installed.


Tip

Add the directive using hostingvietnam.vn.Win32 or Imports hostingvietnam.vn.Win32 at the vị trí cao nhất of your code tệp tin if you haven"t already done so.


"SOFTWAREhostingvietnam.vnNET Framework SetupNDPv4Full";using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey)) if (ndpKey != null && ndpKey.GetValue("Release") != null) Console.WriteLine($".NET Framework Version: CheckFor45PlusVersion((int)ndpKey.GetValue("Release"))"); else Console.WriteLine(".NET Framework Version 4.5 or later is not detected."); // Checking the version using >= enables forward compatibility.string CheckFor45PlusVersion(int releaseKey) if (releaseKey >= 528040) return "4.8 or later"; if (releaseKey >= 461808) return "4.7.2"; if (releaseKey >= 461308) return "4.7.1"; if (releaseKey >= 460798) return "4.7"; if (releaseKey >= 394802) return "4.6.2"; if (releaseKey >= 394254) return "4.6.1"; if (releaseKey >= 393295) return "4.6"; if (releaseKey >= 379893) return "4.5.2"; if (releaseKey >= 378675) return "4.5.1"; if (releaseKey >= 378389) return "4.5"; // This code should never execute. A non-null release key should mean // that 4.5 or later is installed. Return "No 4.5 or later version detected";Private Sub Get45PlusFromRegistry() Const subkey As String = "SOFTWAREhostingvietnam.vnNET Framework SetupNDPv4Full" Using ndpKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey) If ndpKey IsNot Nothing AndAlso ndpKey.GetValue("Release") IsNot Nothing Then Console.WriteLine($".NET Framework Version: CheckFor45PlusVersion(ndpKey.GetValue("Release"))") Else Console.WriteLine(".NET Framework Version 4.5 or later is not detected.") end If kết thúc UsingEnd Sub' Checking the version using >= enables forward compatibility.Private Function CheckFor45PlusVersion(releaseKey As Integer) As String If releaseKey >= 528040 Then Return "4.8 or later" ElseIf releaseKey >= 461808 Then Return "4.7.2" ElseIf releaseKey >= 461308 Then Return "4.7.1" ElseIf releaseKey >= 460798 Then Return "4.7" ElseIf releaseKey >= 394802 Then Return "4.6.2" ElseIf releaseKey >= 394254 Then Return "4.6.1" ElseIf releaseKey >= 393295 Then Return "4.6" ElseIf releaseKey >= 379893 Then Return "4.5.2" ElseIf releaseKey >= 378675 Then Return "4.5.1" ElseIf releaseKey >= 378389 Then Return "4.5" over If ' This code should never execute. A non-null release key should mean ' that 4.5 or later is installed. Return "No 4.5 or later version detected"End FunctionThe example displays output like the following:

.NET Framework Version: 4.6.1This example follows the recommended practice for version checking:

It checks whether the value of the Release entry is greater than or equal to the value of the known release keys.It checks in order from most recent version to earliest version.

Detect .NET Framework 1.0 through 4.0

Each version of .NET Framework from 1.1 to lớn 4.0 is listed as a subkey at HKEY_LOCAL_MACHINESOFTWAREhostingvietnam.vnNET Framework SetupNDP. The following table lists the path to each .NET Framework version. For most versions, there"s an Install REG_DWORD value of 1 to indicate this version is installed. In these subkeys, there"s also a Version REG_SZ value that contains a version string.


Framework VersionRegistry SubkeyValue
1.0HKLMSoftwarehostingvietnam.vn.NETFrameworkPolicyv1.03705Install REG_SZ equals 1
1.1HKLMSoftwarehostingvietnam.vnNET Framework SetupNDPv1.1.4322Install REG_DWORD equals 1
2.0HKLMSoftwarehostingvietnam.vnNET Framework SetupNDPv2.0.50727Install REG_DWORD equals 1
3.0HKLMSoftwarehostingvietnam.vnNET Framework SetupNDPv3.0SetupInstallSuccess REG_DWORD equals 1
3.5HKLMSoftwarehostingvietnam.vnNET Framework SetupNDPv3.5Install REG_DWORD equals 1
4.0 Client ProfileHKLMSoftwarehostingvietnam.vnNET Framework SetupNDPv4ClientInstall REG_DWORD equals 1
4.0 Full ProfileHKLMSoftwarehostingvietnam.vnNET Framework SetupNDPv4FullInstall REG_DWORD equals 1

Important

If the app you"re running is 32-bit và running in 64-bit Windows, the registry paths will be different than previously listed. The 64-bit registry is available in the HKEY_LOCAL_MACHINESOFTWAREWow6432Node subkey. For example, the registry subkey for .NET Framework 3.5 is HKEY_LOCAL_MACHINESOFTWAREWow6432Nodehostingvietnam.vnNET Framework SetupNDPv3.5.


Notice that the registry path lớn the .NET Framework 1.0 subkey is different from the others.

Use Registry Editor (older framework versions)

From the Start menu, choose Run, enter regedit, & then select OK.

You must have administrative credentials to lớn run regedit.

Query the registry using code (older framework versions)

Use the hostingvietnam.vn.Win32.RegistryKey class lớn access the HKEY_LOCAL_MACHINESOFTWAREhostingvietnam.vnNET Framework SetupNDP subkey in the Windows registry.


Important

If the ứng dụng you"re running is 32-bit & running in 64-bit Windows, the registry paths will be different than previously listed. The 64-bit registry is available in the HKEY_LOCAL_MACHINESOFTWAREWow6432Node subkey. For example, the registry subkey for .NET Framework 3.5 is HKEY_LOCAL_MACHINESOFTWAREWow6432Nodehostingvietnam.vnNET Framework SetupNDPv3.5.

Xem thêm: Cắt Ảnh Theo Ý Muốn Trong Photoshop Cực Đơn Giản, Cắt Ảnh Trong Photoshop


The following example finds the versions of .NET Framework 1-4 that are installed:

// xuất hiện the registry key for the .NET Framework entry.using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32). OpenSubKey(
"SOFTWAREhostingvietnam.vnNET Framework SetupNDP")) foreach (var versionKeyName in ndpKey.GetSubKeyNames()) // Skip .NET Framework 4.5 version information. If (versionKeyName == "v4") continue; if (versionKeyName.StartsWith("v")) RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName); // Get the .NET Framework version value. Var name = (string)versionKey.GetValue("Version", ""); // Get the service pack (SP) number. Var sp = versionKey.GetValue("SP", "").ToString(); // Get the installation flag. Var install = versionKey.GetValue("Install", "").ToString(); if (string.IsNullOrEmpty(install)) // No install info; it must be in a child subkey. Console.WriteLine($"versionKeyName name"); else if (install == "1") // Install = 1 means the version is installed. If (!string.IsNullOrEmpty(sp)) Console.WriteLine($"versionKeyName name SPsp"); else Console.WriteLine($"versionKeyName name"); if (!string.IsNullOrEmpty(name)) continue; // else print out info from subkeys... // Iterate through the subkeys of the version subkey. Foreach (var subKeyName in versionKey.GetSubKeyNames()) RegistryKey subKey = versionKey.OpenSubKey(subKeyName); name = (string)subKey.GetValue("Version", ""); if (!string.IsNullOrEmpty(name)) sp = subKey.GetValue("SP", "").ToString(); install = subKey.GetValue("Install", "").ToString(); if (string.IsNullOrEmpty(install)) // No install info; it must be later. Console.WriteLine($"versionKeyName name"); else if (install == "1") if (!string.IsNullOrEmpty(sp)) Console.WriteLine($"subKeyName name SPsp"); else Console.WriteLine($" subKeyName name"); ' Opens the registry key for the .NET Framework entry.Using ndpKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32). OpenSubKey("SOFTWAREhostingvietnam.vnNET Framework SetupNDP") For Each versionKeyName In ndpKey.GetSubKeyNames() ' Skip .NET Framework 4.5 and later. If versionKeyName = "v4" Then Continue For If versionKeyName.StartsWith("v") Then Dim versionKey As RegistryKey = ndpKey.OpenSubKey(versionKeyName) ' Get the .NET Framework version value. Dim name = DirectCast(versionKey.GetValue("Version", ""), String) ' Get the service pack (SP) number. Dim sp = versionKey.GetValue("SP", "").ToString() Dim install = versionKey.GetValue("Install", "").ToString() If String.IsNullOrEmpty(install) Then ' No install info; it must be in a child subkey. Console.WriteLine($"versionKeyName name") ElseIf install = "1" Then If Not String.IsNullOrEmpty(sp) Then Console.WriteLine($"versionKeyName name SPsp") Else Console.WriteLine($"versionKeyName name") kết thúc If end If If Not String.IsNullOrEmpty(name) Then Continue For kết thúc If For Each subKeyName In versionKey.GetSubKeyNames() Dim subKey As RegistryKey = versionKey.OpenSubKey(subKeyName) name = DirectCast(subKey.GetValue("Version", ""), String) If Not String.IsNullOrEmpty(name) Then sp = subKey.GetValue("SP", "").ToString() end If install = subKey.GetValue("Install", "").ToString() If String.IsNullOrEmpty(install) Then ' No install info; it must be later. Console.WriteLine($"versionKeyName name") ElseIf install = "1" Then If Not String.IsNullOrEmpty(sp) Then Console.WriteLine($"subKeyName name SPsp") Else Console.WriteLine($" subKeyName name") end If end If Next kết thúc If NextEnd UsingThe example displays output đầu ra similar to the following:

Find CLR versions

The .NET Framework CLR installed with .NET Framework is versioned separately. There are two ways to lớn detect the version of the .NET Framework CLR:

The Environment class


Important

For .NET Framework 4.5 và later versions, don"t use the Environment.Version property to detect the version of the CLR. Instead, query the registry as described in Detect .NET Framework 4.5 và later versions.


After you have the Version object, query it as follows:

The following example uses the Environment.Version property lớn retrieve CLR version information:

Console.WriteLine($"Version: Environment.Version");Console.WriteLine($"Version: Environment.Version")The example displays output similar to the following: