How to: Determine Which
.NET Framework Versions Are Installed
Users can install and run multiple versions of the .NET Framework on their computers. When you develop or deploy your app, you might need to know which .NET Framework versions are installed on the user’s computer. Note that the .NET Framework consists of two main components, which are versioned separately:
- A set of assemblies, which are collections of types and resources that provide the functionality for your apps. The .NET Framework and assemblies share the same version number.
- The common language runtime (CLR), which manages and executes your app's code. The CLR is identified by its own version number (see .NET Framework Versions and Dependencies).
To get an accurate list of the .NET Framework versions installed on a computer, you can view the registry or query the registry in code:
Viewing the registry (versions 1-4)
Viewing the registry (version 4.5 and later)
Using code to query the registry (versions 1-4)
Using code to query the registry (version 4.5 and later)
Viewing the registry (version 4.5 and later)
Using code to query the registry (versions 1-4)
Using code to query the registry (version 4.5 and later)
To find the CLR version, you can use a tool or code:
For information about detecting the installed updates for each version of the .NET Framework, see How to: Determine Which .NET Framework Updates Are Installed. For information about installing the .NET Framework, see the installation guide.
To find .NET Framework versions by viewing the registry (.NET Framework 1-4)
- On the Start menu, choose Run.
- In the Open box, enter regedit.exe.You must have administrative credentials to run regedit.exe.
- In the Registry Editor, open the following subkey:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDPThe installed versions are listed under the NDP subkey. The version number is stored in the Version entry. For the .NET Framework 4 the Version entry is under the Client or Full subkey (under NDP), or under both subkeys.
Note The "NET Framework Setup" folder in the registry does not begin with a period.
To find .NET Framework versions by viewing the registry (.NET Framework 4.5 and later)
- On the Start menu, choose Run.
- In the Open box, enter regedit.exe.You must have administrative credentials to run regedit.exe.
- In the Registry Editor, open the following subkey:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\FullCheck for a DWORD value named Release. The existence of the Release DWORD indicates that the .NET Framework 4.5 or newer has been installed on that computer.The value of the Release DWORD indicates which version of the .NET Framework is installed.Value of the Release DWORDVersion378389.NET Framework 4.5378675.NET Framework 4.5.1 installed with Windows 8.1378758.NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2379893.NET Framework 4.5.2
To find .NET Framework versions by querying the registry in code (.NET Framework 1-4)
- Use the Microsoft.Win32::RegistryKey class to access the Software\Microsoft\NET Framework Setup\NDP\ subkey under HKEY_LOCAL_MACHINE in the Windows registry.The following code shows an example of this query.
Note This code does not show how to detect .NET Framework 4.5 or later. Check the Release DWORD to detect those versions, as described in the previous section.The example produces output that's similar to the following:v2.0.50727 2.0.50727.4016 SP2 v3.0 3.0.30729.4037 SP2 v3.5 3.5.30729.01 SP1 v4 Client 4.0.30319 Full 4.0.30319
To find .NET Framework versions by querying the registry in code (.NET Framework 4.5 and later)
- The existence of the Release DWORD indicates that the .NET Framework 4.5 or later has been installed on a computer. The value of the keyword indicates the installed version. To check this keyword, use the OpenBaseKey and OpenSubKey methods of the Microsoft.Win32::RegistryKey class to access the Software\Microsoft\NET Framework Setup\NDP\v4.0\Full subkey under HKEY_LOCAL_MACHINE in the Windows registry.
- Check the value of the Release keyword to determine the installed version. Here are the .NET Framework versions and associated Release keywords.VersionValue of the Release DWORD.NET Framework 4.5378389.NET Framework 4.5.1 installed with Windows 8.1378675.NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2378758.NET Framework 4.5.2379893Here's an example of this query:The example produces output that's similar to the following:
The .NET Framework version 4.5.1 is installed
To find the current runtime version by using the Clrver tool
- Use the CLR Version Tool (Clrver.exe) to determine which versions of the common language runtime are installed on a computer.From a Visual Studio Command Prompt, enter clrver. This command produces output similar to the following:
Versions installed on the machine: v2.0.50727 v4.0.30319
For more information about using this tool, see Clrver.exe (CLR Version Tool).
To find the current runtime version by querying the Environment class in code
- Query the Version property of the Environment class to identify the version of the runtime that is currently executing the code. You can use the Version::Majorproperty to get the major release identifier (for example, "4" for version 4.0), the Version::Minor property to get the minor release identifier (for example, "0" for version 4.0), or the Object::ToString method to get the entire version string (for example, "4.0.30319.18010", as shown in the following code). This property returns a single value that reflects the version of the runtime that is currently executing the code; it does not return assembly versions or other versions of the runtime that may have been installed on the computer.Here's an example of querying the Environment::Version property for runtime version information:The example produces output that's similar to the following:
Version: 4.0.30319.18010
How to: Determine Which
.NET Framework Updates Are Installed
The installed updates for each version of the .NET Framework installed on a computer are listed in the Windows registry. You can use the Registry Editor (regedit.exe) to view this information.
In the Registry Editor, the .NET Framework versions and installed updates for each version are stored in different subkeys. For information about detecting the installed version numbers, see How to: Determine Which .NET Framework Versions Are Installed. For information about installing the .NET Framework, see theinstallation guide.
To find installed updates
- On the Start menu, choose Run.
- In the Open box, enter regedit.exe.You must have administrative credentials to run regedit.exe.
- In the Registry Editor, open the following subkey:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\UpdatesThe installed updates are listed under subkeys that identify the .NET Framework version they apply to. Each update is identified by a Knowledge Base (KB) number.
Example
The following code programmatically determines the .NET Framework updates that are installed on a computer. You must have administrative credentials to run this example.
The example produces output that's similar to the following:
Microsoft .NET Framework 3.5 SP1 KB953595 Hotfix for Microsoft .NET Framework 3.5 SP1 (KB953595) SP1 KB2657424 Security Update for Microsoft .NET Framework 3.5 SP1 (KB2657424) KB958484 Hotfix for Microsoft .NET Framework 3.5 SP1 (KB958484) KB963707 Update for Microsoft .NET Framework 3.5 SP1 (KB963707) Microsoft .NET Framework 4 Client Profile KB2160841 Security Update for Microsoft .NET Framework 4 Client Profile (KB2160841) KB2446708 Security Update for Microsoft .NET Framework 4 Client Profile (KB2446708) KB2468871 Update for Microsoft .NET Framework 4 Client Profile (KB2468871) KB2478663 Security Update for Microsoft .NET Framework 4 Client Profile (KB2478663) KB2518870 Security Update for Microsoft .NET Framework 4 Client Profile (KB2518870) KB2533523 Update for Microsoft .NET Framework 4 Client Profile (KB2533523) KB2539636 Security Update for Microsoft .NET Framework 4 Client Profile (KB2539636) KB2572078 Security Update for Microsoft .NET Framework 4 Client Profile (KB2572078) KB2633870 Security Update for Microsoft .NET Framework 4 Client Profile (KB2633870) KB2656351 Security Update for Microsoft .NET Framework 4 Client Profile (KB2656351) Microsoft .NET Framework 4 Extended KB2416472 Security Update for Microsoft .NET Framework 4 Extended (KB2416472) KB2468871 Update for Microsoft .NET Framework 4 Extended (KB2468871) KB2487367 Security Update for Microsoft .NET Framework 4 Extended (KB2487367) KB2533523 Update for Microsoft .NET Framework 4 Extended (KB2533523) KB2656351 Security Update for Microsoft .NET Framework 4 Extended (KB2656351)
沒有留言:
張貼留言