Write a simple operational registry class in the morning. Now, let everyone help me see, please contact me if you have any questions.
Using system; using microsoft.win32;
Namespace PowerComponent {/// Operation Registry Public Class Register {/// Instance Construction Function PUBLIC Register () {// Todo: Add Construction Function Logic here
#Region Public Method /// Write Registry, if the specified item already exists, modify the value of the specified item /// Registry Basic enumeration param> /// Registration item, excluding the foundation param> /// Value name param> /// Value param > /// returns a Boolean value, whether or not the operation succeeds returns> public bool setValue (XjxComponent.Register.keyType keytype, string key, string name, string values) {try {RegistryKey rk = (RegistryKey) getRegistryKey ( Keytype); RegistryKey RKT = RK.CreateSubKey (key); if (rkt! = null) rkt.setValue (Name, VALUES); Else {throw (New Exception ");} Return True;} catCh {returnaf false;}}
/// Read Registry /// Registry Basic enumeration param> /// Registration item, excluding basic param > /// Value name param> /// Return strings returns> public string getValue (xjxcomponent.register.keytype keytype, string key, string name) {TRING {RegistryKey rk = (registryKey) getRegistryKey (keytype); registryKey rkt = rk.opensubKey (key);
IF (rkt! = null) Return RKT.GetValue (Name) .tostring (); else throw ("Unable to find specified item");} catch (exception ex) {return ex. measure;}
}
/// Delete the value in the registry /// Registry Basic enumeration param> /// Registry Name, excluding param> /// Value Name param> /// Returns the Boolean value, specifies whether the operation is successful returns> public bool deletevalue (xjxcomponent.register.keytype keytype, string key, string name) {try {RegistryKey rk = (RegistryKey) getRegistryKey (keytype); RegistryKey rkt = rk.OpenSubKey (key, true);! if (rkt = null) rkt.DeleteValue (name, true); else throw (New Exception ("If you cannot find a specified item"); Return True;} catch {return false;}}
/// Delete the specified item in the registry /// Registry Basic enumeration param> /// The item in the registry, does not include item yl param> /// returns a Boolean value, whether or not the operation succeeds returns> public bool deleteSubKey (XjxComponent.Register.keyType keytype, string key) {try {RegistryKey rk = (RegistryKey) getRegistryKey (keytype RK.DELETESUBKEYTREE (KEY); RETURN TRUE;} catCh {returnaf false;}}
/// Determine if the specified item exists /// Classic enumeration param> /// Specify key string param> /// < Returns> Returns the Boolean value to indicate whether the specified item exists returns> public bool ISEXIST (xjxcomponent.register.keytype keytype, string key) {registryKey rk = (registryKey) getRegistryKey (keytype);
IF (rk.opensubKey (key) == null) Return False; else return
/// Retrieve all values associated with the specified item /// Classic enumeration param> /// Specify item string param> // / returns a string associated with the specified item array of all values returns> public string [] getValues (XjxComponent.Register.keyType keytype, string key) {RegistryKey rk = (RegistryKey) getRegistryKey (keytype); RegistryKey rkt = RK.OpenSubKey (key); if (rkt! = null) {string [] names = rkt.getValuenames (); if (Names.Length == 0) Return Names; else {string [] values = new string [names. Length]; int i = 0; forward (String name in name) {VALUES [I] = rkt.getValue (name) .tostring (); i ;} returnis;}} else {throw (new exception " does not exist")); } }
#ndregion
#Region Private method
/// Return RegistryKey Object /// Registry Classic enumeration param> /// returns> private object getRegistryKey (xjxcomponent.register.keytype keytype) {registryKey rk = null; switch (keytype) {case keyType.HKEY_CLASS_ROOT: rk = Registry.ClassesRoot; break; case keyType.HKEY_CURRENT_USER: rk = Registry.CurrentUser; break; case keyType.HKEY_LOCAL_MACHINE: rk = Registry.LocalMachine; break; case keyType . = = Registration.Users; Break; Case keytype.hKey_current_config: rk = registry.currentconfig; Break;} Return RK;}
#ndregion