■ 레지스트리 설정을 쓰는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
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 |