using System; using Microsoft.Win32; namespace MyNameSpace { public class Registry { public Registry() { } public bool CreateKey(RegistryHive RootKey, string SubKey) { bool blRetVal; RegistryKey RKey = RegistryKey.OpenRemoteBaseKey(RootKey,String.Empty); blRetVal = false; try { RegistryKey RSubKey = RKey.CreateSubKey(SubKey); blRetVal = true; RSubKey.Close(); } catch { blRetVal = false; } RKey.Close(); return blRetVal; } public object GetValue(RegistryHive RootKey, string SubKey, string ValueName, object DefaultValue) { object oRetVal; RegistryKey RKey = RegistryKey.OpenRemoteBaseKey(RootKey,String.Empty); oRetVal = null; try { RegistryKey RSubKey = RKey.OpenSubKey(SubKey); oRetVal = RSubKey.GetValue(ValueName, DefaultValue); RSubKey.Close(); } catch { oRetVal = DefaultValue; } RKey.Close(); return oRetVal; } public bool SetValue(RegistryHive RootKey, string SubKey, string ValueName, object Value) { bool blRetVal; RegistryKey RKey = RegistryKey.OpenRemoteBaseKey(RootKey,String.Empty); blRetVal = false; try { RegistryKey RSubKey = RKey.OpenSubKey(SubKey,true); RSubKey.SetValue(ValueName, Value); RSubKey.Close(); blRetVal = true; } catch { blRetVal = false; } RKey.Close(); return blRetVal; } } }
|