









using System; using System.IO; using System.Runtime.InteropServices; using System.Text; using Microsoft.Win32; namespace Components { ///
public class RegCtrl { private static RegistryKey rootkey; ///
public RegCtrl(string RootKey) { switch (RootKey.ToUpper()) { case "CLASSES_ROOT": rootkey=Registry.ClassesRoot; break; case "CURRENT_USER": rootkey=Registry.CurrentUser; break; case "LOCAL_MACHINE": rootkey=Registry.LocalMachine; break; case "USERS": rootkey=Registry.Users; break; case "CURRENT_CONFIG": rootkey=Registry.CurrentConfig; break; case "DYN_DATA": rootkey=Registry.DynData; break; case "PERFORMANCE_DATA": rootkey=Registry.PerformanceData; break; default: rootkey=Registry.CurrentUser; break; } } ///
///
///
///
///
public string GetRegVal(string keypath,string keyname,string def) { try { RegistryKey key=rootkey.OpenSubKey(keypath); return key.GetValue(keyname,(object)def).ToString(); } catch { return def; } } ///
///
///
///
public bool SetRegVal(string keypath,string keyname,string keyval) { try { RegistryKey key=rootkey.OpenSubKey(keypath,true); key.SetValue(keyname,(object)keyval); return true; } catch { return false; } } ///
///
///
public RegistryKey CreateRegKey(string keypath) { try { return rootkey.CreateSubKey(keypath); } catch { return null; } } ///
///
///
public bool DelRegSubKey(string keypath) { try { rootkey.DeleteSubKey(keypath); return true; } catch { return false; } } ///
///
///
public bool DelRegSubKeyTree(string keypath) { try { rootkey.DeleteSubKeyTree(keypath); return true; } catch { return false; } } ///
///
///
///
public bool DelRegKeyVal(string keypath,string keyname) { try { RegistryKey key=rootkey.OpenSubKey(keypath,true); key.DeleteValue(keyname); return true; } catch { return false; } } } }
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。