Compartir a través de


CLR Version Detection Technology Sample

This sample shows how to detect which versions of the .NET Framework common language runtime (CLR) are installed on a computer.

For information about using the samples, see the following topics:

To build the sample using Visual Studio

  1. Open Windows Explorer and navigate to the CP subdirectory under the CLRVerSample directory.

  2. Double-click the icon for CLRVerCP.sln to open it in Visual Studio 2005.

  3. On the Build menu, click Build Solution.

To run the sample

  1. In the Command Prompt window, navigate to the directory that contains the new executable.

  2. Type CLRVer.exe at the command line.

Requirements

.NET Framework Version: 2.0, 1.1

Microsoft Visual Studio 2005

These samples require Windows headers which are available to your project if you build using Microsoft Visual Studio 2005, the Visual Studio 2005 Command Prompt, or if you have the Platform SDK installed and specified in an include path.

Remarks

This sample is available only in C++. The sample code calls unmanaged APIs that are defined in mscoree.h, which is included in the \include subdirectory under your .NET Framework SDK installation directory, to list the versions of the CLR that are installed on the local computer.

This sample calls the unmanaged GetRequestedRuntimeInfo method, which returns information about the CLR version loaded into the process. This information does not always show the latest CLR version installed on the computer.

In the .NET Framework version 2.0, you can get the latest installed CLR version by specifying the following for the GetRequestedRuntimeInfo parameters:

  • The first three parameters as null.

  • The RUNTIME_INFO_UPGRADE_VERSION flag in the RUNTIME_INFO_FLAGS enumerations specified for the runtimeInfoFlags parameter.

The GetRequestedRuntimeInfo method may not return the latest CLR version in the following circumstances:

  • If an application configuration file exists that specifies loading a particular CLR version. Note that the .NET Framework will use the configuration file even if null is specified for pConfigurationFile parameter.

  • If CorBindToRuntimeEx was called specifying an earlier CLR version.

  • If an application is currently running that was compiled for an earlier CLR version.

See Also

Reference

GetCORVersion

Concepts

Runtime Hosts

Other Resources

Hosting the Common Language Runtime
Unmanaged API Reference