Esempio n. 1
0
 /// <summary>
 /// Set Value/StartValue depending if it set...
 /// True = Check in the list also
 /// </summary>
 /// <returns>Weither its set or not</returns>
 public bool CheckStartValue()
 {
     try
     {
         using (RegistryKey key = RegistrySet.OpenSubKey(RegKey, true))
             if (key != null && key.GetValue(Value) != null && key.GetValue(Value).Equals(CheckValue))
             {
                 return(true);
             }
             else if (key == null || key.GetValue(Value) == null)
             {
                 return(DefaultValue);
             }
     } catch (Exception ex) {
         Console.WriteLine(ex);
     }
     return(false);
 }
Esempio n. 2
0
 public RegistryHelper(RegistrySet set, string path, bool writable)
 {
     InitRegistry(set, path, writable);
 }
Esempio n. 3
0
        private void InitRegistry(RegistrySet set, string path, bool writable)
        {
            var registryKey = set.Equals(RegistrySet.LocalMachine) ? Registry.LocalMachine : Registry.CurrentUser;

            mRegistryKey = registryKey.OpenSubKey(path, writable);
        }
Esempio n. 4
0
 public RegistryHelper(RegistrySet set, string path)
 {
     InitRegistry(set, path, false);
 }
Esempio n. 5
0
 /// <summary>
 /// Do the actual effect at the system
 /// </summary>
 public bool DoToggle()
 {
     try
     {
         using (RegistryKey key = RegistrySet.OpenSubKey(RegKey, true))
         {
             if (key != null)
             {
                 if (Active)
                 {
                     if (UncheckValue == null)
                     {
                         if (key.GetValue(Value) != null)
                         {
                             key.DeleteValue(Value);
                         }
                     }
                     else if (UncheckValue.GetType() == typeof(int))
                     {
                         key.SetValue(Value, UncheckValue, ValueKind);
                     }
                 }
                 else
                 {
                     if (CheckValue == null)
                     {
                         if (key.GetValue(Value) != null)
                         {
                             key.DeleteValue(Value);
                         }
                     }
                     else if (CheckValue.GetType() == typeof(int))
                     {
                         key.SetValue(Value, CheckValue, ValueKind);
                     }
                 }
             }
             else if (key == null)
             {
                 if (Active)
                 {
                     if (UncheckValue.GetType() == typeof(int))
                     {
                         Registry.SetValue(RegistrySet + "\\" + RegKey, Value, UncheckValue, ValueKind);
                     }
                 }
                 else
                 {
                     if (CheckValue.GetType() == typeof(int))
                     {
                         Registry.SetValue(RegistrySet + "\\" + RegKey, Value, CheckValue, ValueKind);
                         //key.SetValue(Value, CheckValue, ValueKind);
                     }
                 }
             }
         }
         if (RestartExplorer)
         {
             foreach (Process p in Process.GetProcesses())
             {
                 try // In case we get Access Denied
                 {
                     if (p.ProcessName == "explorer")
                     {
                         p.Kill();
                         break;
                     }
                 }
                 catch { }
             }
             Process.Start("explorer.exe");
         }
         return(true); //Success
     }
     catch (Exception)
     {
         return(false); //Some exception error...
     }
 }