반응형
public static class RegistryUtil
{
    public static string GetValue(string path, string keyName)
    {
        try
        {
            string strValue = null;
 
            RegistryKey regKey = Registry.CurrentUser.CreateSubKey(path, RegistryKeyPermissionCheck.ReadWriteSubTree);
 
            var value = regKey.GetValue(keyName);
            if (value != null)
            {
                strValue = value.ToString();
            }
 
            return strValue;
        }
        catch (Exception)
        {
            return string.Empty;
        }
    }
 
    public static void SetKey(string path, string name, string value)
    {
        RegistryKey regKey = Registry.CurrentUser.CreateSubKey(path, RegistryKeyPermissionCheck.ReadWriteSubTree);
 
        regKey.SetValue(name, value, RegistryValueKind.String);
    }
 
    public static void DeleteKey(string path, string name)
    {
        RegistryKey regKey = Registry.CurrentUser.CreateSubKey(path, RegistryKeyPermissionCheck.ReadWriteSubTree);
 
        regKey.DeleteValue(name, false);
    }
 
    public static void DeleteRegistry(string path)
    {
        Registry.CurrentUser.DeleteSubKey(path);
    }
 
    public static void SetSoftwareKey(string path, string name, string value)
    {
        SetKey(@"Software\" + path, name, value);
    }
 
    public static string GetSoftwareValue(string path, string name)
    {
        return GetValue(@"Software\" + path, name);
    }
}
반응형

+ Recent posts