첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170
using Microsoft.Win32;

using DSCore.Core;

#region 레지스트리 설정 쓰기 - WriteRegistrySetting(applicationName, groupName, valueName, value)

/// <summary>
/// 레지스트리 설정 쓰기
/// </summary>
/// <param name="applicationName">애플리케이션명</param>
/// <param name="groupName">그룹명</param>
/// <param name="valueName">값 명칭</param>
/// <param name="value">값</param>
public void WriteRegistrySetting(string applicationName, string groupName, string valueName, object value)
{
    RegistryManager rootRegistryManager        = null;
    RegistryManager applicationRegistryManager = null;
    RegistryManager moduleRegistryManager      = null;

    try
    {
        rootRegistryManager = new RegistryManager(Registry.CurrentUser);

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

        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(moduleRegistryManager.CreateChildRegistryKey(groupChildRegistryKey));
        }

        try
        {
            moduleRegistryManager.SetValue(valueName, value);
        }
        catch
        {
        }
    }
    finally
    {
        if(applicationRegistryManager != null)
        {
            applicationRegistryManager.Close();
        }

        if(rootRegistryManager != null)
        {
            rootRegistryManager.Close();
        }

        if(moduleRegistryManager != null)
        {
            moduleRegistryManager.Close();
        }
    }
}

#endregion
728x90
반응형
그리드형
Posted by 사용자 icodebroker

댓글을 달아 주세요