public static bool NetFrameworkInstalled(NETFX version, int sp_level)
        {
            bool   result  = false;
            string regPath = "";

            switch (version)
            {
            case NETFX.v20:
                regPath = REG_NETFX20;
                break;

            case NETFX.v30:
                regPath = REG_NETFX30;
                break;

            case NETFX.v35:
                regPath = REG_NETFX35;
                break;

            case NETFX.v40:
                regPath = REG_NETFX40;
                break;

            default:
                return(false);
            }

            try
            {
                RegistryKey key = Registry.LocalMachine;
                key = key.OpenSubKey(regPath);
                if (key == null)
                {
                    return(false);
                }

                // check if installed
                object value = key.GetValue(REG_VAL_INSTALLED);
                if (value != null)
                {
                    if (int.Parse(value.ToString()) == 1)
                    {
                        result = true;
                    }
                }

                // check if SP level is equal to/higher than requested
                if (result && (sp_level > 0))
                {
                    value = key.GetValue(REG_VAL_SP);
                    if (value != null)
                    {
                        result = (int.Parse(value.ToString()) >= sp_level);
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                System.Windows.Forms.MessageBox.Show(
                    "An error occured while checking if the .NET Framework " + version.ToString() + " is installed"
                    + Environment.NewLine + Environment.NewLine + ex.ToString(),
                    "Error",
                    System.Windows.Forms.MessageBoxButtons.OK,
                    System.Windows.Forms.MessageBoxIcon.Error);
            }

            return(result);
        }
        public static bool NetFrameworkInstalled(NETFX version, int sp_level)
        {
            bool result = false;
            string regPath = "";

            switch (version)
            {
                case NETFX.v20:
                    regPath = REG_NETFX20;
                    break;
                case NETFX.v30:
                    regPath = REG_NETFX30;
                    break;
                case NETFX.v35:
                    regPath = REG_NETFX35;
                    break;
                case NETFX.v40:
                    regPath = REG_NETFX40;
                    break;
                default:
                    return false;
            }

            try
            {
                RegistryKey key = Registry.LocalMachine;
                key = key.OpenSubKey(regPath);
                if (key == null)
                    return false;

                // check if installed
                object value = key.GetValue(REG_VAL_INSTALLED);
                if (value != null)
                    if (int.Parse(value.ToString()) == 1)
                        result = true;

                // check if SP level is equal to/higher than requested
                if (result && (sp_level > 0))
                {
                    value = key.GetValue(REG_VAL_SP);
                    if (value != null)
                        result = (int.Parse(value.ToString()) >= sp_level);
                }
            }
            catch (Exception ex)
            {
                result = false;
                System.Windows.Forms.MessageBox.Show(
                    "An error occured while checking if the .NET Framework " + version.ToString() + " is installed"
                        + Environment.NewLine + Environment.NewLine + ex.ToString(),
                    "Error",
                    System.Windows.Forms.MessageBoxButtons.OK,
                    System.Windows.Forms.MessageBoxIcon.Error);
            }

            return result;
        }
 public static bool NetFrameworkInstalled(NETFX version)
 {
     return(NetFrameworkInstalled(version, 0));
 }
 public static bool NetFrameworkInstalled(NETFX version)
 {
     return NetFrameworkInstalled(version, 0);
 }