첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ 설치 닷넷 프레임워크 버전 리스트 구하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


Program.cs

 

 

using Microsoft.Win32;

using System;

using System.Collections.Generic;

 

namespace TestProject

{

    /// <summary>

    /// 프로그램

    /// </summary>

    class Program

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Static

        //////////////////////////////////////////////////////////////////////////////// Private

 

        #region 프로그램 시작하기 - Main()

 

        /// <summary>

        /// 프로그램 시작하기

        /// </summary>

        private static void Main()

        {

            Console.Title = "설치 닷넷 프레임워크 버전 리스트 구하기";

 

            List<string> versionList = GetDotNetFrameworkVersionList();

 

            foreach(string version in versionList)

            {

                Console.WriteLine(version);

            }

        }

 

        #endregion

 

        #region 닷넷 프레임워크 버전 리스트 구하기 - GetDotNetFrameworkVersionList()

 

        /// <summary>

        /// 닷넷 프레임워크 버전 리스트 구하기

        /// </summary>

        /// <returns>닷넷 프레임워크 버전 리스트</returns>

        private static List<string> GetDotNetFrameworkVersionList()

        {

            List<string> list = new List<string>();

 

            using

            (

                RegistryKey ndpRegistryKey = RegistryKey.OpenRemoteBaseKey

                (

                    RegistryHive.LocalMachine,

                    string.Empty

                ).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\")

            )

            {

                foreach(string versionKeyName in ndpRegistryKey.GetSubKeyNames())

                {

                    if(versionKeyName.StartsWith("v"))

                    {

                        RegistryKey versionKey = ndpRegistryKey.OpenSubKey(versionKeyName);

 

                        string version = versionKey.GetValue("Version", string.Empty).ToString();

                        string sp      = versionKey.GetValue("SP"     , string.Empty).ToString();

                        string install = versionKey.GetValue("Install", string.Empty).ToString();

 

                        if(install == string.Empty)

                        {

                            list.Add($"{versionKeyName} {version}");

                        }

                        else

                        {

                            if(sp != string.Empty && install == "1")

                            {

                                list.Add($"{versionKeyName} {version} SP{sp}");

                            }

                        }

 

                        if(version != string.Empty)

                        {

                            continue;

                        }

 

                        foreach(string subKeyName in versionKey.GetSubKeyNames())

                        {

                            RegistryKey subRegistryKey = versionKey.OpenSubKey(subKeyName);

 

                            version = (string)subRegistryKey.GetValue("Version", string.Empty);

 

                            if(version != string.Empty)

                            {

                                sp = subRegistryKey.GetValue("SP", "").ToString();

                            }

 

                            install = subRegistryKey.GetValue("Install", string.Empty).ToString();

 

                            if(install != string.Empty)

                            {

                                list.Add($"{versionKeyName} {version}");

                            }

                            else

                            {

                                if(sp != string.Empty && install == "1")

                                {

                                    list.Add($" {subKeyName} {version} SP{sp}");

                                }

                                else if(install == "1")

                                {

                                    list.Add($" {subKeyName} {version}");

                                }

                            }

                        }

                    }

                }

            }

 

            return list;

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요