Informationen über das akt. verwendete .NET-Framework abfragen

using System;
using System.IO;
using Microsoft.Win32;

/// <summary>
/// freeware helper class for getting .NET framework info
/// (W) 2011 by admin of codezentrale.de
/// </summary>
public static class NETFrameworkInfo
{
    /// <summary>
    /// prints the root install path of the .NET-Frameworks on your system
    /// </summary>
    /// <returns>.NET root install path</returns>
    public static string NETRootPath
    {
        get
        {
            string rootpath = string.Empty;

            try
            {
                RegistryKey rKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework");

                if (rKey != null)
                {
                    rootpath = rKey.GetValue("InstallRoot").ToString();
                }
            }
            catch (Exception e)
            {
                rootpath = e.Message;
            }

            return rootpath;
        }
    }
    /// <summary>
    /// prints currently used CLR version string
    /// hint: .NET 3.0 & 3.5 are using CLR v2.0!
    /// </summary>
    /// <returns>currently used CLR version</returns>
    public static string CurrentCLRVersion
    {
        get
        {
            return Environment.Version.ToString();
        }
    }
    /// <summary>
    /// prints the currently used .NET version home directory
    /// hint: .NET 3.0 & 3.5 are using CLR v2.0, so the homedir for the CLR-DLLs is v2.X !
    /// </summary>
    /// <returns>the currently used .NET version home directory</returns>
    public static string CurrentCLRVersionHome
    {
        get
        {
            string sRetVal = string.Empty;

            string sRootPath = NETRootPath;

            if (!string.IsNullOrEmpty(sRootPath))
            {
                sRetVal = Path.Combine(sRootPath, "v" + Environment.Version.Major.ToString() + "." + Environment.Version.Minor.ToString() + "." + Environment.Version.Build.ToString());

                if (!Directory.Exists(sRetVal))
                {
                    sRetVal = string.Empty;
                }
            }

            return sRetVal;
        }
    }
}