Created
October 1, 2013 13:31
-
-
Save yemrekeskin/6778481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class RegistryConfigurator | |
| { | |
| private static RegistryKey baseRegistryKey = Registry.LocalMachine; | |
| public static RegistryKey BaseRegistryKey | |
| { | |
| get { return baseRegistryKey; } | |
| set { baseRegistryKey = value; } | |
| } | |
| private static string subKey = "SOFTWARE\\My-Application"; | |
| public static string SubKey | |
| { | |
| get { return subKey; } | |
| set { subKey = value; } | |
| } | |
| public static string ReadKey(string Key) | |
| { | |
| ThrowError(Key); | |
| RegistryKey rgstryKey = baseRegistryKey.OpenSubKey(subKey); | |
| return rgstryKey == null ? null : (string)rgstryKey.GetValue(Key); | |
| } | |
| public static bool DeleteKey(string Key) | |
| { | |
| ThrowError(Key); | |
| RegistryKey rgstryKey = baseRegistryKey.CreateSubKey(subKey); | |
| if (rgstryKey == null) | |
| return false; | |
| else | |
| rgstryKey.DeleteValue(Key); | |
| return true; | |
| } | |
| public static bool Write(string Key, object Value) | |
| { | |
| ThrowError(Key); | |
| try | |
| { | |
| RegistryKey rgstryKey = baseRegistryKey.CreateSubKey(subKey); | |
| rgstryKey.SetValue(Key.ToUpper(), Value); | |
| } | |
| catch (Exception ex) | |
| { | |
| throw new ApplicationException(ex.Message); | |
| } | |
| return true; | |
| } | |
| public static bool DeleteSubKeyTree() | |
| { | |
| try | |
| { | |
| RegistryKey rgstryKey = baseRegistryKey.OpenSubKey(subKey); | |
| if (rgstryKey != null) | |
| baseRegistryKey.DeleteSubKeyTree(subKey); | |
| return true; | |
| } | |
| catch (Exception ex) | |
| { | |
| return false; | |
| } | |
| } | |
| private static void ThrowError(string value) | |
| { | |
| if (String.IsNullOrEmpty(value)) | |
| throw new ApplicationException("Your Key is Null..."); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment