Keywords: .NET Framework | Version Detection | Registry Keys
Abstract: This article provides a comprehensive guide on detecting .NET Framework versions and service packs using registry keys, with code examples in C# and PowerShell, and discussion on version dependencies and considerations for 32-bit and 64-bit systems.
Introduction
The .NET Framework is a critical component for many Windows applications, and detecting installed versions and service packs is essential for compatibility and deployment. This article outlines official methods based on registry queries, supplemented with code examples.
Overview of Registry-Based Detection
The registry is the recommended approach for detecting .NET Framework versions. Different versions correspond to specific registry keys and values, categorized into versions 1.0-4.0 and 4.5 and later.
Detection for .NET Framework 1.0 to 4.0
For versions 1.0 to 4.0, inspect specific subkeys under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\. Key registry keys and values are as follows:
<table><tr><th>Framework Version</th><th>Registry Key</th><th>Value</th></tr><tr><td>1.0</td><td>HKLM\Software\Microsoft\.NETFramework\Policy\v1.0\3705</td><td>Install REG_SZ equals 1</td></tr><tr><td>1.1</td><td>HKLM\Software\Microsoft\NET Framework Setup\NDP\v1.1.4322</td><td>Install REG_DWORD equals 1</td></tr><tr><td>2.0</td><td>HKLM\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727</td><td>Install REG_DWORD equals 1</td></tr><tr><td>3.0</td><td>HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.0\Setup</td><td>InstallSuccess REG_DWORD equals 1</td></tr><tr><td>3.5</td><td>HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.5</td><td>Install REG_DWORD equals 1</td></tr><tr><td>4.0 Client Profile</td><td>HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Client</td><td>Install REG_DWORD equals 1</td></tr><tr><td>4.0 Full Profile</td><td>HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Full</td><td>Install REG_DWORD equals 1</td></tr>Note: .NET 1.0 uses a string value, while others use DWORD values. On 64-bit Windows for 32-bit applications, check the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ subkey.
Detection for .NET Framework 4.5 and Later
For versions 4.5 and later, check the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full subkey. If this subkey exists and contains a Release REG_DWORD value, it indicates installation of 4.5 or higher. The Release value corresponds to specific versions:
<table><tr><th>.NET Framework Version</th><th>Release Value</th></tr><tr><td>4.5</td><td>378389</td></tr><tr><td>4.5.1</td><td>378675 (on Windows 8.1 and Server 2012 R2) or 378758 (on others)</td></tr><tr><td>4.5.2</td><td>379893</td></tr><tr><td>4.6</td><td>393295 (on Windows 10) or 393297 (on others)</td></tr><tr><td>4.6.1</td><td>394254 (on Windows 10 November Update) or 394271 (on others)</td></tr><tr><td>4.6.2</td><td>394802 (on Windows 10 Anniversary Update and Server 2016) or 394806 (on others)</td></tr><tr><td>4.7</td><td>460798 (on Windows 10 Creators Update) or 460805 (on others)</td></tr><tr><td>4.7.1</td><td>461308 (on Windows 10 Fall Creators Update and Server 1709) or 461310 (on others)</td></tr><tr><td>4.7.2</td><td>461808 (on Windows 10 April 2018 Update and Server 1803) or 461814 (on others)</td></tr><tr><td>4.8</td><td>528040 (on Windows 10 May 2019 Update and November 2019 Update) or 528372 (on other Windows 10 updates) or 528449 (on Windows 11 and Server 2022) or 528049 (on others)</td></tr><tr><td>4.8.1</td><td>533509 (on Windows 11 2025 Update) or 533320 (on Windows 11 2022 and 2023 Update) or 533325 (on others)</td></tr>By comparing the Release value, you can determine the exact version. For example, a value greater than or equal to 528040 indicates .NET 4.8 or later.
Service Pack Detection
Service pack levels can be detected using similar registry keys. For instance, for .NET 1.1, check the SP value at HKLM\Software\Microsoft\NET Framework Setup\NDP\v1.1.4322\SP. Other versions follow a similar pattern:
<table><tr><th>Framework Version</th><th>Service Pack Registry Key</th></tr><tr><td>1.1</td><td>HKLM\Software\Microsoft\NET Framework Setup\NDP\v1.1.4322\SP</td></tr><tr><td>2.0</td><td>HKLM\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727\SP</td></tr><tr><td>3.0</td><td>HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.0\SP</td></tr><tr><td>3.5</td><td>HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.5\SP</td></tr><tr><td>4.0 Client Profile</td><td>HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Client\Servicing</td></tr><tr><td>4.0 Full Profile</td><td>HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Full\Servicing</td></tr>For .NET 1.0, service pack information is stored under HKLM\Software\Microsoft\Active Setup\Installed Components\ with specific GUIDs, and the version string format is #,#,####,#, where the last digit indicates the service pack level.
Code Examples
The following code examples demonstrate how to programmatically detect .NET Framework versions.
C# Example (for .NET 4.5+)
using Microsoft.Win32;
using System;
class Program
{
static void Main()
{
const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
using (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
using (RegistryKey ndpKey = baseKey.OpenSubKey(subkey))
{
if (ndpKey != null && ndpKey.GetValue("Release") != null)
{
int releaseKey = (int)ndpKey.GetValue("Release");
string version = CheckFor45PlusVersion(releaseKey);
Console.WriteLine($".NET Framework Version: {version}");
}
else
{
Console.WriteLine(".NET Framework Version 4.5 or later is not detected.");
}
}
}
static string CheckFor45PlusVersion(int releaseKey)
{
if (releaseKey >= 533320) return "4.8.1 or later";
if (releaseKey >= 528040) return "4.8";
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";
return "No 4.5 or later version detected";
}
}This code checks the Release value and returns the corresponding version string, using >= comparisons for forward compatibility.
PowerShell Example
$release = Get-ItemPropertyValue -LiteralPath 'HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -Name Release
if ($release -ge 378389) { Write-Host ".NET Framework 4.5 or later installed" }
else { Write-Host ".NET Framework 4.5 or later not detected" }This PowerShell script simply checks the Release value and outputs relevant information. It can be extended with a switch statement for multiple versions.
Dependencies Between Versions
Some .NET Framework versions have dependencies. For example, .NET 3.0 adds functionality to .NET 2.0, so detecting .NET 3.0 requires .NET 2.0 to be installed. Similarly, .NET 3.5 depends on both .NET 2.0 and 3.0. .NET 4.0 introduces a new CLR (version 4.0) that can run side-by-side with CLR 2.0, so there are no strict dependencies.
Additional Notes
On 64-bit Windows, 32-bit applications should check the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ subkey. Alternative methods include using Control Panel (Programs and Features) or community-maintained tools. For CLR version detection, use the Clrver.exe tool or the Environment.Version property, but the latter is not recommended for detecting installed versions in .NET 4.5 and later.
Conclusion
Detecting .NET Framework versions via the registry is a reliable and automatable method. The code and tables provided in this article assist developers in quickly implementing version checks to ensure application compatibility across environments. It is advisable to incorporate error handling and logging in real-world deployments.