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

■ 레지스트리 설정 쓰기

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

using Microsoft.Win32;

 

using DS.Core;

 

#region 레지스트리 설정 읽기 - ReadRegistrySetting(applicationName, groupName, valueName)

 

/// <summary>

/// 레지스트리 설정 읽기

/// </summary>

/// <param name="applicationName">애플리케이션명</param>

/// <param name="groupName">그룹명</param>

/// <param name="valueName">값 명칭</param>

/// <returns>레지스트리 설정</returns>

public object ReadRegistrySetting(string applicationName, string groupName, string valueName)

{

    RegistryManager rootRegistryManager        = null;

    RegistryManager applicationRegistryManager = null;

    RegistryManager moduleRegistryManager      = null;

 

    object value = null;

 

    try

    {

        string applicationChildRegistryKey = string.Format("Software\\{0}", applicationName);

        string groupChildRegistryKey       = groupName;

 

        rootRegistryManager = new RegistryManager(Registry.CurrentUser);


        applicationRegistryManager = new RegistryManager

        (

            rootRegistryManager.OpenChildRegistryKey

            (

                applicationChildRegistryKey,

                true

            )

        );

 

        if(applicationRegistryManager.RegistryKey == null)

        {

            applicationRegistryManager = new RegistryManager

            (

                rootRegistryManager.CreateChildRegistryKey(applicationChildRegistryKey)

            );

        }

 

        moduleRegistryManager = new RegistryManager

        (

            applicationRegistryManager.OpenChildRegistryKey(groupChildRegistryKey)

        );

 

        if(moduleRegistryManager.RegistryKey == null)

        {

            moduleRegistryManager = new RegistryManager

            (

                applicationRegistryManager.CreateChildRegistryKey(groupChildRegistryKey)

            );

        }

 

        value = moduleRegistryManager.GetValue(valueName);

    }

    finally

    {

        if(applicationRegistryManager != null)

        {

            applicationRegistryManager.Close();

        }

 

        if(rootRegistryManager != null)

        {

            rootRegistryManager.Close();

        }

 

        if(moduleRegistryManager != null)

        {

            moduleRegistryManager.Close();

        }

    }

 

    return value;

}

 

#endregion

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

Posted by 사용자 icodebroker

댓글을 달아 주세요