public RegistryChangeMonitor(RegistrySetting registrySetting)
 {
     this.RegistrySettings = new List <RegistrySetting>();
     this.RegistrySettings.Add(registrySetting);
     this.RegistryPath = (RegistryHelper.GetRegistryHiveLongName(registrySetting.RegistryHive) + @"\" + registrySetting.SubKeyPath).ToUpper();
     this._filter      = REG_NOTIFY_CHANGE.LAST_SET;
 }
Esempio n. 2
0
 private void InitializeRegistrySetting()
 {
     foreach (string key in ConfigurationManager.AppSettings.AllKeys)
     {
         if (key.StartsWith("RegistrySetting"))
         {
             RegistrySetting registrySetting = RegistrySetting.Parse(ConfigurationManager.AppSettings[key]);
             RegistrySettings.Add(registrySetting);
             RegistryHelper.SetRegistryValue(registrySetting);
             MaintainRegistrySetting(registrySetting);
         }
     }
 }
Esempio n. 3
0
 public static object GetRegistryValue(RegistrySetting registrySetting)
 {
     using (RegistryKey baseKey = RegistryKey.OpenBaseKey(registrySetting.RegistryHive, RegistryView.Registry64))
     {
         using (RegistryKey key = baseKey.OpenSubKey(registrySetting.SubKeyPath, false))
         {
             if (key == null)
             {
                 throw new Exception(string.Format("Key does not exist: {0}", registrySetting.FullKeyPath));
             }
             return(key.GetValue(registrySetting.Name));
         }
     }
 }
Esempio n. 4
0
        private void MaintainRegistrySetting(RegistrySetting registrySetting)
        {
            RegistryChangeMonitor monitor = RegistryChangeMonitors.ContainsKey(registrySetting.FullKeyPath)
                ? RegistryChangeMonitors[registrySetting.FullKeyPath]
                : null;

            if (monitor == null)
            {
                monitor          = new RegistryChangeMonitor(registrySetting);
                monitor.Changed += RegistrySettingChanged;
                monitor.Start();
                RegistryChangeMonitors.Add(registrySetting.FullKeyPath, monitor);
            }
            else
            {
                monitor.AddRegistrySetting(registrySetting);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Parses a RegistrySetting represented as a single pipe-delimited string (e.g., "HKCU\Console\CursorSize|DWORD|25").
        /// </summary>
        /// <param name="text">String representing a RegistrySetting</param>
        /// <returns>New <see cref="RegistrySetting"/> instance.</returns>
        public static RegistrySetting Parse(string text)
        {
            RegistrySetting setting = new RegistrySetting();

            string[] settingSegments = text.Split(new char[1] {
                '|'
            }, 3);
            List <string> pathSegments = new List <string>(settingSegments[0].Split('\\'));

            if (settingSegments.Length != 3)
            {
                throw new Exception("setting must consist of three pipe-delimited segments: full path, value kind, and value");
            }
            if (pathSegments.Count < 3)
            {
                throw new Exception("Registry key path must consist of at least three backslash-delimited segments: hive, subkey path, and name");
            }

            // RegistryHive
            setting.RegistryHive = RegistryHelper.GetRegistryHive(pathSegments[0]);

            // SubKeyPath
            setting.SubKeyPath = string.Join(@"\", pathSegments.GetRange(1, pathSegments.Count - 2));

            // Name
            setting.Name = pathSegments[pathSegments.Count - 1];

            // RegistryValueKind
            setting.RegistryValueKind = RegistryHelper.GetValueKind(settingSegments[1]);

            // Value
            switch (setting.RegistryValueKind)
            {
            case RegistryValueKind.DWord: setting.Value = uint.Parse(settingSegments[2]); break;

            case RegistryValueKind.QWord: setting.Value = ulong.Parse(settingSegments[2]); break;

            case RegistryValueKind.String: setting.Value = settingSegments[2]; break;

            default: throw new Exception("Unsupported registry value kind: " + settingSegments[1]);
            }

            return(setting);
        }
 public void AddRegistrySetting(RegistrySetting registrySetting)
 {
     this.RegistrySettings.Add(registrySetting);
 }
Esempio n. 7
0
 public static bool SetRegistryValue(RegistrySetting registrySetting)
 {
     return(SetRegistryValue(registrySetting.RegistryHive, registrySetting.SubKeyPath, registrySetting.Name, registrySetting.Value, registrySetting.RegistryValueKind));
 }
Esempio n. 8
0
 public static ulong GetRegistryQWordValue(RegistrySetting registrySetting)
 {
     return((ulong)GetRegistryValue(registrySetting));
 }
Esempio n. 9
0
 public static uint GetRegistryDWordValue(RegistrySetting registrySetting)
 {
     return((uint)GetRegistryValue(registrySetting));
 }
Esempio n. 10
0
 public static string GetRegistryStringValue(RegistrySetting registrySetting)
 {
     return((string)GetRegistryValue(registrySetting));
 }
Esempio n. 11
0
 private void RestoreRegistrySetting(RegistrySetting registrySetting)
 {
     RegistryHelper.SetRegistryValue(registrySetting);
 }