Using system; using microsoft.win32;
Namespace PowerComponent {/// /// Operation Registration /// summary> public class register {
/// /// instance constructor /// summary> public register () {// // Todo: Add constructor logic //}
#Region Public Method
/// /// Write the registry, if the specified item already exists, modify the value of the specified item /// summary> /// Registry Basic enumeration param> /// Registration item, does not include the foundation param> /// Value name param> /// Value param> /// Returns the Boolean value, specifying the operation successfully returns> public bool setValue (xjxcomponent.register.keytype keytype, string key, string name, string value) {TRY {RegistryKey rk = (registryKey) getRegistryKey (KeyType);
RegistryKey rkt = rk.createSubKey (key); if (rkt! = Null) rkt.setValue (name, value); else {throw (New Exception ");}
Return True;} catch {return false;}
}
/// /// read registry /// summary> /// Registry Classic enumeration param> /// Registry item, does not include the foundation param> /// Value name param> /// Returns RETURns> Public String getValue (xjxcomponent. Register.keytype keytype, string key, string name) {Try {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;}
}
/// /// Remove the value in the registry /// summary> /// Registry Basic enumeration param> /// Registration form name, does not include the foundation 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 "));
Return True;
} CatCh {returnaf false;}}
/// /// Remove the specified item in the registry ///////////////////////////////////////////////////////////> Enumeration param> /// Registry, does not include the basic param> /// Return to Boolean value, specify whether the operation is successful returns> public bool deleteSubkey (xjxcomponent.register.keytype Keytype, String Key ) {Try {registryKey rk = (registryKey) getRegistryKey (keytype);
RK.DELETESUBKEYTREE (Key);
Return True;
} CatCh {returnaf false;}}
/// /// Judgment does the specified item exists /// summary> /// Classic enumeration param> /// Specify item string param> /// Returns the Boolean value, indicating 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
/// /// Retrieves all values associated with the specified item /// summary> /// Classic enumeration param> /// Specified item string param> /// Returns the strings of all values of the specified items returns> public string [] getValues (xjxcomponent.register.keytype keytype, string key) {registryKey RK = (registryKey) GetRegistryKey (keytype); registryKey rkt = rk.opensubkey (key);
IF (rkt! = null) {string [] name = rkt.getValuenames ();
IF (Names.Length == 0) Return Names; Else {String [] Values = new string [names.length];
INT i = 0;
FOREACH (String Name in Names) {Values [i] = rkt.getValue (name) .tostring ();
i ;
Return Values;
}} Else {throw (new exception "));}}
#ndregion
#Region Private method
/// /// Returns RegistryKey object /// summary> /// 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.HKEY_USERS: rk = Registry.Users; break; case keyType.HKEY_CURRENT_CONFIG: rk = Registry.CurrentConfig; break;}
Return rk;}
#ndregion
#Region enumeration /// /// Registry Classic enumeration /// summary> public enum keytype: int {/// /// Registry Classic HKEY_CLASSES_ROOT / / / < / summary> hkey_class_root = 0, /// /// Registry Classic hkey_current_user /// summary> hkey_current_user = 1, /// /// Registry Code HKEY_LOCAL_MACHINE / / / < / summary> HKEY_LOCAL_MACHINE = 2, /// /// Registry Classic hkey_users /// summary> hkey_users = 3, /// /// Registry Classic HKEY_CURRENT_CONFIG /// < / summary> hkey_current_config = 4} #ENDREGON}}}