첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.00MB

▶ Program.cs

using Microsoft.Win32;
using System;

namespace TestProject
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

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

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            string displayName = "Bandizip";
            string version     = GetInstalledProgramVersion(displayName, out _);

            Console.WriteLine($"{displayName} : {version}");
        }

        #endregion
        #region 설치 프로그램 버전 구하기 - GetInstalledProgramVersion(displayName)

        /// <summary>
        /// 설치 프로그램 버전 구하기
        /// </summary>
        /// <param name="displayName">디스플레이명</param>
        /// <returns>설치 프로그램 버전</returns>
        private static string GetInstalledProgramVersion(string displayName, out bool is32BitVersion)
        {
            string parentKeyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

            using(RegistryKey parentKey = Registry.LocalMachine.OpenSubKey(parentKeyName))
            {
                foreach(string childKeyName in parentKey.GetSubKeyNames())
                {
                    using(RegistryKey childKey = parentKey.OpenSubKey(childKeyName))
                    {
                        try
                        {
                            string name = childKey.GetValue("DisplayName")?.ToString();

                            if(name == displayName)
                            {
                                is32BitVersion = false;

                                return childKey.GetValue("DisplayVersion")?.ToString();
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }

            parentKeyName = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";

            using(RegistryKey parentKey = Registry.LocalMachine.OpenSubKey(parentKeyName))
            {
                foreach(string childKeyName in parentKey.GetSubKeyNames())
                {
                    using(RegistryKey childKey = parentKey.OpenSubKey(childKeyName))
                    {
                        try
                        {
                            string name = childKey.GetValue("DisplayName")?.ToString();

                            if(name == displayName)
                            {
                                is32BitVersion = true;

                                return childKey.GetValue("DisplayVersion")?.ToString();
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }

            is32BitVersion = false;

            return null;
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요