Ejemplo n.º 1
0
        public static Boolean Exists(RegistryKeyType type, string path)
        {
            Boolean     bExist = false;
            RegistryKey rk;

            if (type == RegistryKeyType.CurrentUser)
            {
                rk = Registry.CurrentUser;
            }
            else
            {
                rk = Registry.LocalMachine;
            }

            RegistryKey registry = rk.OpenSubKey(path);

            if (registry == null)
            {
                return(bExist);
            }
            bExist = true;
            registry.Close();

            return(bExist);
        }
Ejemplo n.º 2
0
        private void SetRegistryKey(String KeyName, String SubKeyName, String Value, RegistryKeyType myType)
        {
            String ActualValue = "";

            if (myType == RegistryKeyType.String)
            {
                RegistryValueKind myRegistryValueKind = RegistryValueKind.String;
                try
                {
                    Registry.SetValue(KeyName, SubKeyName, Value, myRegistryValueKind);
                    ActualValue = (String)Registry.GetValue(KeyName, SubKeyName, "");
                }
                catch (Exception e)
                {
                    // do nothing.
                }
            }
            if (myType == RegistryKeyType.DWord)
            {
                RegistryValueKind myRegistryValueKind = RegistryValueKind.DWord;
                try
                {
                    int ValueCopy_Int = Convert.ToInt32(Value);
                    Registry.SetValue(KeyName, SubKeyName, ValueCopy_Int, myRegistryValueKind);
                    ActualValue = Convert.ToString(Registry.GetValue(KeyName, SubKeyName, ""));
                }
                catch (Exception e)
                {
                    // do nothing.
                }
            }

            richTextBox_Status.Text += "Setting " + SubKeyName + " to: " + ActualValue + "\n";
        }
Ejemplo n.º 3
0
        private void lvKeyDisplay_DoubleClick(object sender, EventArgs e)
        {
            TreeNode selectedNode = tvRegistryNavigator.SelectedNode;

            if (selectedNode == null)
            {
                return;
            }
            if (lvKeyDisplay.SelectedItems.Count < 1)
            {
                return;
            }
            if (lvKeyDisplay.View == View.List)
            {
                return;
            }
            string key = lvKeyDisplay.SelectedItems[0].Text;

            using (editRegistryKeyForm erkf = new editRegistryKeyForm(key))
            {
                if (erkf.ShowDialog() == DialogResult.OK)
                {
                    RegistryKeyType  regKey = keyFromNode(GetRootNode(selectedNode));
                    RegistryNodeData data   = (RegistryNodeData)selectedNode.Tag;
                    Client.Send((byte)NetworkCommand.RegistryEdit, (byte)RegistryCommand.SetValue, (byte)regKey, data.Path, key, erkf.NewValue);
                    data.LoadedValues = false;
                    LoadValues(selectedNode);
                }
            }
        }
Ejemplo n.º 4
0
 static extern int NtSetValueKey(
     SafeRegistryHandle KeyHandle,
     UnicodeString ValueName,
     int TitleIndex,
     RegistryKeyType Type,
     byte[] Data,
     int DataSize);
Ejemplo n.º 5
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode selectedNode = tvRegistryNavigator.SelectedNode;

            if (selectedNode == null)
            {
                return;
            }
            if (lvKeyDisplay.SelectedItems.Count < 1)
            {
                return;
            }
            if (lvKeyDisplay.View == View.List)
            {
                return;
            }
            string key = lvKeyDisplay.SelectedItems[0].Text;

            if (MessageBox.Show(string.Format("Delete the registry key {0}?", key), "Delete registry key", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                RegistryKeyType  regKey = keyFromNode(GetRootNode(selectedNode));
                RegistryNodeData data   = (RegistryNodeData)selectedNode.Tag;
                Client.Send((byte)NetworkCommand.RegistryEdit, (byte)RegistryCommand.DeleteValue, (byte)regKey, data.Path, key);
                data.LoadedValues = false;
                LoadValues(selectedNode);
            }
        }
Ejemplo n.º 6
0
        void LoadValues(TreeNode Node)
        {
            if (Node == null)
            {
                return;
            }
            if (IsLoading)
            {
                return;
            }
            RegistryNodeData data = (RegistryNodeData)Node.Tag;

            if (data.LoadedValues)
            {
                UpdateVauesFromRegistryData(data);
                return;
            }
            IsLoading    = true;
            UpdatingNode = Node;
            TreeNode rootNode = GetRootNode(Node);

            Invoke((MethodInvoker) delegate()
            {
                lvKeyDisplay.Items.Clear();
                lvKeyDisplay.View = View.List;
                lvKeyDisplay.Items.Add("Loading...");
            });

            RegistryKeyType key = keyFromNode(rootNode);

            Client.Send((byte)NetworkCommand.RegistryEdit, (byte)RegistryCommand.UpdateKeys, (byte)key, data.Path);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Writes the value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type">The type.</param>
        /// <param name="regKey">The reg key.</param>
        /// <param name="name">The name.</param>
        /// <param name="value">The value.</param>
        /// <param name="valueKind">Kind of the value.</param>
        public static void WriteValue <T>(RegistryKeyType type, string regKey, string name, T value, RegistryValueKind valueKind)
        {
            RegistryKey oRegKey = null;

            switch (type)
            {
            case RegistryKeyType.CurrentUser:
                oRegKey = Registry.CurrentUser;
                break;

            case RegistryKeyType.LocalMachine:
                oRegKey = Registry.LocalMachine;
                break;
            }

            try
            {
                oRegKey = oRegKey.OpenSubKey(regKey, true);
                oRegKey.GetValue(name);
                Debug.WriteLine("Leggo " + name);
                oRegKey.SetValue(name, value, valueKind);
            }
            finally
            {
                oRegKey.Close();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 检索指定项关联的所有值
        /// </summary>
        /// <param name="keytype">基项枚举</param>
        /// <param name="key">指定项字符串</param>
        /// <returns>返回指定项关联的所有值的字符串数组</returns>
        public string[] GetValues(RegistryKeyType keytype, string key)
        {
            RegistryKey rk       = (RegistryKey)GetRegistryKey(keytype);
            RegistryKey software = rk.OpenSubKey(baseKey, true);
            RegistryKey rkt      = software.OpenSubKey(key);

            string[] names = 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);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 返回RegistryKey对象
        /// </summary>
        /// <param name="keyType">注册表基项枚举</param>
        /// <returns></returns>
        private object GetRegistryKey(RegistryKeyType keyType)
        {
            if (keyType.Equals(RegistryKeyType.HKEY_CLASS_ROOT))
            {
                return(Registry.ClassesRoot);
            }

            if (keyType.Equals(RegistryKeyType.HKEY_CURRENT_USER))
            {
                return(Registry.CurrentUser);
            }

            if (keyType.Equals(RegistryKeyType.HKEY_LOCAL_MACHINE))
            {
                return(Registry.LocalMachine);
            }

            if (keyType.Equals(RegistryKeyType.HKEY_USERS))
            {
                return(Registry.Users);
            }

            if (keyType.Equals(RegistryKeyType.HKEY_CURRENT_CONFIG))
            {
                return(Registry.CurrentConfig);
            }

            return(null);
        }
Ejemplo n.º 10
0
 static extern uint NtSetValueKey(
     UIntPtr KeyHandle,
     IntPtr ValueName,
     int TitleIndex,
     RegistryKeyType Type,
     IntPtr Data,
     int DataSize
     );
Ejemplo n.º 11
0
        /// <summary>
        /// 删除注册表中的指定项
        /// </summary>
        /// <param name="keytype">注册表基项枚举</param>
        /// <param name="key">注册表中的项,不包括基项</param>
        /// <returns>返回布尔值,指定操作是否成功</returns>
        public void DeleteSubKey(RegistryKeyType keytype, string key)
        {
            RegistryKey rk       = (RegistryKey)GetRegistryKey(keytype);
            RegistryKey software = rk.OpenSubKey(baseKey, true);

            if (software != null)
            {
                software.DeleteSubKeyTree(key);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Reads the value.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="path">The path.</param>
        /// <param name="name">The name.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns></returns>
        internal static object ReadValue(RegistryKeyType type, string path, string name, object defaultValue)
        {
            RegistryKey rk;
            object      value = null;

            if (type == RegistryKeyType.CurrentUser)
            {
                rk = Registry.CurrentUser;
            }
            else
            {
                rk = Registry.LocalMachine;
            }

            RegistryKey registry = rk.OpenSubKey(path);


            try
            {
                object readValue = registry.GetValue(name);

                if (defaultValue is string && readValue is string[])
                {
                    string[] temp1 = (string[])readValue;

                    if (temp1.Length > 0)
                    {
                        value = temp1[0];
                    }
                    else
                    {
                        value = defaultValue;
                    }
                }
                else
                {
                    value = readValue;
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Errore duranting read of subkey registry " + name + " of key " + path + ". " + e.Message);
                value = defaultValue;
            }

            if (value == null)
            {
                value = defaultValue;
            }

            registry.Close();

            return(value);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 写入注册表,如果指定项已经存在,则修改指定项的值
        /// </summary>
        /// <param name="keytype">注册表基项枚举</param>
        /// <param name="key">注册表项,不包括基项</param>
        /// <param name="name">值名称</param>
        /// <param name="values">值</param>
        public void SetValue(RegistryKeyType keytype, string key, string name, string values)
        {
            RegistryKey rk       = (RegistryKey)GetRegistryKey(keytype);
            RegistryKey software = rk.OpenSubKey(baseKey, true);
            RegistryKey rkt      = software.CreateSubKey(key);

            if (rkt != null)
            {
                rkt.SetValue(name, values);
            }
        }
Ejemplo n.º 14
0
        public bool Open(RegistryKeyType keyType, bool createIfDoesNotExist = false)
        {
            try
            {
                return(Open(keyType, SubKey, createIfDoesNotExist));
            }
            catch (Exception exception)
            {
                Log.Error(exception);

                return(false);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 读取注册表
        /// </summary>
        /// <param name="keytype">注册表基项枚举</param>
        /// <param name="key">注册表项,不包括基项</param>
        /// <param name="name">值名称</param>
        /// <returns>返回字符串</returns>
        public string GetValue(RegistryKeyType keytype, string key, string name)
        {
            RegistryKey rk       = (RegistryKey)GetRegistryKey(keytype);
            RegistryKey software = rk.OpenSubKey(baseKey, true);
            RegistryKey rkt      = software.OpenSubKey(key);

            if (rkt != null)
            {
                return(rkt.GetValue(name).ToString());
            }

            return(string.Empty);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 判断指定项是否存在
        /// </summary>
        /// <param name="keytype">基项枚举</param>
        /// <param name="key">指定项字符串</param>
        /// <returns>返回布尔值,说明指定项是否存在</returns>
        public bool IsExist(RegistryKeyType keytype, string key)
        {
            RegistryKey rk       = (RegistryKey)GetRegistryKey(keytype);
            RegistryKey software = rk.OpenSubKey(baseKey);
            RegistryKey rkt      = software.OpenSubKey(key);

            if (rkt != null)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 删除注册表中的值
        /// </summary>
        /// <param name="keytype">注册表基项枚举</param>
        /// <param name="key">注册表项名称,不包括基项</param>
        /// <param name="name">值名称</param>
        public void DeleteValue(RegistryKeyType keytype, string key, string name)
        {
            RegistryKey rk       = (RegistryKey)GetRegistryKey(keytype);
            RegistryKey software = rk.OpenSubKey(baseKey, true);
            RegistryKey rkt      = software.OpenSubKey(key, true);

            if (rkt != null)
            {
                object value = rkt.GetValue(name);
                if (value != null)
                {
                    rkt.DeleteValue(name, true);
                }
            }
        }
Ejemplo n.º 18
0
        private static RegistryKey KeyFromType(RegistryKeyType type)
        {
            switch (type)
            {
            case RegistryKeyType.CurrentUser: return(Registry.CurrentUser);

            case RegistryKeyType.LocalMachine: return(Registry.LocalMachine);

            case RegistryKeyType.ClassesRoot: return(Registry.ClassesRoot);

            case RegistryKeyType.UserRoot: return(Registry.Users);

            case RegistryKeyType.CurrentConfig: return(Registry.CurrentConfig);

            default: return(null);
            }
        }
Ejemplo n.º 19
0
        public static void Delete(RegistryKeyType keyType, string subKey)
        {
            try
            {
                if (!Exists(keyType, subKey))
                {
                    return;
                }

                using (var registry = new Registry(keyType, subKey))
                {
                    registry.Delete();
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 将对象所有属性写入指定注册表中
        /// </summary>
        /// <param name="keyType">注册表基项枚举</param>
        /// <param name="key">注册表项,不包括基项</param>
        /// <param name="obj">传入的对象</param>
        public void SetObjectValue(RegistryKeyType keyType, string key, Object obj)
        {
            if (obj != null)
            {
                Type t = obj.GetType();

                string name;
                object value;
                foreach (var p in t.GetProperties())
                {
                    if (p != null)
                    {
                        name  = p.Name;
                        value = p.GetValue(obj, null);
                        this.SetValue(keyType, key, name, value.ToString());
                    }
                }
            }
        }
Ejemplo n.º 21
0
        protected RegistryKey OpenSubKey(RegistryKeyType keyType, string subKey)
        {
            try
            {
                if (subKey == null)
                {
                    throw new Exception("Input parameter 'subKey' is blank.");
                }

                if (keyType == RegistryKeyType.ClassesRoot)
                {
                    return(Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(subKey));
                }
                if (keyType == RegistryKeyType.CurrentConfig)
                {
                    return(Microsoft.Win32.Registry.CurrentConfig.OpenSubKey(subKey));
                }
                if (keyType == RegistryKeyType.CurrentUser)
                {
                    return(Microsoft.Win32.Registry.CurrentUser.OpenSubKey(subKey));
                }
                if (keyType == RegistryKeyType.LocalMachine)
                {
                    return(Microsoft.Win32.Registry.LocalMachine.OpenSubKey(subKey));
                }
                if (keyType == RegistryKeyType.PerformanceData)
                {
                    return(Microsoft.Win32.Registry.PerformanceData.OpenSubKey(subKey));
                }
                if (keyType == RegistryKeyType.Users)
                {
                    return(Microsoft.Win32.Registry.Users.OpenSubKey(subKey));
                }
                throw new Exception("Input parameter 'keyType' is not implemented.");
            }
            catch (Exception exception)
            {
                Log.Error(exception);

                return(null);
            }
        }
Ejemplo n.º 22
0
        public bool Open(RegistryKeyType keyType, string subKey, bool createIfDoesNotExist = false)
        {
            try
            {
                Close();

                this._keyType = keyType;

                _key = createIfDoesNotExist ? CreateSubKey(keyType, subKey) : OpenSubKey(keyType, subKey);

                this._subKey = subKey;

                return(IsOpen);
            }
            catch (Exception exception)
            {
                Log.Error(exception);

                return(false);
            }
        }
Ejemplo n.º 23
0
        public static bool Exists(RegistryKeyType keyType, string subKey)
        {
            try
            {
                using (var registry = new Registry(keyType, subKey, false))
                {
                    if (registry.IsOpen)
                    {
                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);

                return(false);
            }
        }
Ejemplo n.º 24
0
        bool RefreshNode(TreeNode Node)
        {
            if (Node.Equals(LoadingNode))
            {
                return(true);
            }
            RegistryNodeData data = (RegistryNodeData)Node.Tag;

            if (!data.LoadedNodes)
            {
                if (IsLoading)
                {
                    return(true);
                }
                IsLoading = true;

                if (Node.Nodes.Count > 0)
                {
                    Node.Nodes.Remove(Node.FirstNode);
                }
                Node.Nodes.Add(LoadingNode);

                UpdatingNode = Node;

                TreeNode rootNode = GetRootNode(Node);


                RegistryKeyType key = keyFromNode(rootNode);

                Console.WriteLine("Root Node: {0}", rootNode.Text);

                string path = data.Path;

                Console.WriteLine("Node path: {0}", path);

                Client.Send((byte)NetworkCommand.RegistryEdit, (byte)RegistryCommand.UpdateNodes, (byte)key, path);
            }
            return(false);
        }
Ejemplo n.º 25
0
        public static void Create(RegistryKeyType keyType, string subKey)
        {
            try
            {
                if (Exists(keyType, subKey))
                {
                    return;
                }

                using (var registry = new Registry(keyType, subKey, true))
                {
                    if (!registry.IsOpen)
                    {
                        throw new Exception("Could not create registry key " + keyType + "\\" + subKey);
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
Ejemplo n.º 26
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode selectedNode = tvRegistryNavigator.SelectedNode;

            if (selectedNode == null)
            {
                return;
            }
            if (lvKeyDisplay.View == View.List)
            {
                return;
            }
            using (addRegistryKeyForm arkf = new addRegistryKeyForm())
            {
                if (arkf.ShowDialog() == DialogResult.OK)
                {
                    RegistryKeyType  regKey = keyFromNode(GetRootNode(selectedNode));
                    RegistryNodeData data   = (RegistryNodeData)selectedNode.Tag;
                    Client.Send((byte)NetworkCommand.RegistryEdit, (byte)RegistryCommand.SetValue, (byte)regKey, data.Path, arkf.NewKey, arkf.NewValue);
                    data.LoadedValues = false;
                    LoadValues(selectedNode);
                }
            }
        }
Ejemplo n.º 27
0
 public RegistryKey( string name, byte[] value )
 {
     this.Type = RegistryKeyType.Binary;
     this.Name = name;
     this.ValueB = value;
 }
Ejemplo n.º 28
0
 public Registry(RegistryKeyType keyType, string subKey, bool createIfDoesNotExist = false)
 {
     Open(keyType, subKey, createIfDoesNotExist);
 }
Ejemplo n.º 29
0
        protected RegistryKey OpenSubKey(RegistryKeyType keyType, string subKey)
        {
            try
              {
            if (subKey == null)
            {
              throw new Exception("Input parameter 'subKey' is blank.");
            }

            if (keyType == RegistryKeyType.ClassesRoot)
            {
              return Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(subKey);
            }
            if (keyType == RegistryKeyType.CurrentConfig)
            {
              return Microsoft.Win32.Registry.CurrentConfig.OpenSubKey(subKey);
            }
            if (keyType == RegistryKeyType.CurrentUser)
            {
              return Microsoft.Win32.Registry.CurrentUser.OpenSubKey(subKey);
            }
            if (keyType == RegistryKeyType.LocalMachine)
            {
              return Microsoft.Win32.Registry.LocalMachine.OpenSubKey(subKey);
            }
            if (keyType == RegistryKeyType.PerformanceData)
            {
              return Microsoft.Win32.Registry.PerformanceData.OpenSubKey(subKey);
            }
            if (keyType == RegistryKeyType.Users)
            {
              return Microsoft.Win32.Registry.Users.OpenSubKey(subKey);
            }
            throw new Exception("Input parameter 'keyType' is not implemented.");
              }
              catch (Exception exception)
              {
            Log.Error(exception);

            return null;
              }
        }
Ejemplo n.º 30
0
        protected static void WriteToFile(StreamWriter streamWriter,
                                      Registry registry,
                                      RegistryKeyType keyType,
                                      string subKey)
        {
            try
              {
            string line = "";

            try
            {
              line = "[" + ((RegistryNodeType)keyType);

              if (!String.IsNullOrEmpty(subKey))
              {
            line += "\\" + subKey;
              }

              line += "]";

              streamWriter.WriteLine(line);

              if (!registry.Open(keyType, subKey))
              {
            line = "ERROR - COULD NOT OPEN";

            streamWriter.WriteLine(line);

            return;
              }
            }
            catch (Exception exception)
            {
              line = "ERROR - " + exception.Message.ToUpper();

              streamWriter.WriteLine(line);

              return;
            }

            string[] valueNames = registry.GetValueNames();

            if (valueNames == null)
            {
              line = "ERROR - COULD NOT GET VALUE NAMES";

              streamWriter.WriteLine(line);
            }
            else
            {
              foreach (string valueName in valueNames)
              {
            if (String.IsNullOrEmpty(valueName))
            {
              line = "@=";
            }
            else
            {
              line = "\"" + valueName + "\"=";
            }

            object value = registry.GetValue(valueName);

            if (value == null)
            {
              line += "NULL";
            }
            else
            {
              line += "\"" + value + "\"";
            }

            try
            {
              streamWriter.WriteLine(line);
            }
            catch (Exception exception)
            {
              line = "ERROR - " + exception.Message.ToUpper();

              streamWriter.WriteLine(line);
            }
              }
            }

            streamWriter.WriteLine("");

            string[] subKeyNames = registry.GetSubKeyNames();

            if (subKeyNames == null)
            {
              line = "ERROR - COULD NOT GET SUBKEY NAMES";

              streamWriter.WriteLine(line);
            }
            else
            {
              foreach (string subKeyName in subKeyNames)
              {
            string subKeyPath = "";

            if (String.IsNullOrEmpty(subKey))
            {
              subKeyPath = subKeyName;
            }
            else
            {
              subKeyPath = subKey + "\\" + subKeyName;
            }

            WriteToFile(streamWriter, registry, keyType, subKeyPath);
              }
            }
              }
              catch (Exception exception)
              {
            Log.Error(exception);
              }
        }
Ejemplo n.º 31
0
 /// <summary>
 /// Reads the int value.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="path">The path.</param>
 /// <param name="name">The name.</param>
 /// <param name="defaultValue">The default value.</param>
 /// <returns></returns>
 public static int ReadIntValue(RegistryKeyType type, string path, string name, int defaultValue)
 {
     return((int)ReadValue(type, path, name, defaultValue));
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Reads the byte array value.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="path">The path.</param>
 /// <param name="name">The name.</param>
 /// <returns></returns>
 public static byte[] ReadByteArrayValue(RegistryKeyType type, string path, string name)
 {
     byte[] def = new byte[0];
     return((byte[] )ReadValue(type, path, name, def));
 }
Ejemplo n.º 33
0
        public static void Delete(RegistryKeyType keyType, string subKey)
        {
            try
              {
            if (!Exists(keyType, subKey))
            {
              return;
            }

            using (var registry = new Registry(keyType, subKey))
            {
              registry.Delete();
            }
              }
              catch (Exception exception)
              {
            Log.Error(exception);
              }
        }
Ejemplo n.º 34
0
        public static void Create(RegistryKeyType keyType, string subKey)
        {
            try
              {
            if (Exists(keyType, subKey))
            {
              return;
            }

            using (var registry = new Registry(keyType, subKey, true))
            {
              if (!registry.IsOpen)
              {
            throw new Exception("Could not create registry key " + keyType + "\\" + subKey);
              }
            }
              }
              catch (Exception exception)
              {
            Log.Error(exception);
              }
        }
Ejemplo n.º 35
0
 private static RegistryKey KeyFromType(RegistryKeyType type)
 {
     switch(type)
     {
         case RegistryKeyType.CurrentUser: return Registry.CurrentUser;
         case RegistryKeyType.LocalMachine: return Registry.LocalMachine;
         case RegistryKeyType.ClassesRoot: return Registry.ClassesRoot;
         case RegistryKeyType.UserRoot: return Registry.Users;
         case RegistryKeyType.CurrentConfig: return Registry.CurrentConfig;
         default: return null;
     }
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Writes the byte array value.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="regKey">The reg key.</param>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 public static void WriteByteArrayValue(RegistryKeyType type, string regKey, string name, byte[] value)
 {
     WriteValue(type, regKey, name, value, RegistryValueKind.Binary);
 }
Ejemplo n.º 37
0
        public static bool Exists(RegistryKeyType keyType, string subKey)
        {
            try
              {
            using (var registry = new Registry(keyType, subKey, false))
            {
              if (registry.IsOpen)
              {
            return true;
              }

              return false;
            }
              }
              catch (Exception exception)
              {
            Log.Error(exception);

            return false;
              }
        }
Ejemplo n.º 38
0
 public RegistryKey( string name, string value )
 {
     this.Type = RegistryKeyType.String;
     this.Name = name;
     this.ValueS = value;
 }
Ejemplo n.º 39
0
        public bool Open(RegistryKeyType keyType, bool createIfDoesNotExist = false)
        {
            try
              {
            return Open(keyType, SubKey, createIfDoesNotExist);
              }
              catch (Exception exception)
              {
            Log.Error(exception);

            return false;
              }
        }
Ejemplo n.º 40
0
 /// <summary>
 /// Reads the string value.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="path">The path.</param>
 /// <param name="name">The name.</param>
 /// <returns></returns>
 public static string ReadStringValue(RegistryKeyType type, string path, string name)
 {
     return((string)ReadValue(type, path, name, ""));
 }
Ejemplo n.º 41
0
        public bool Open(RegistryKeyType keyType, string subKey, bool createIfDoesNotExist = false)
        {
            try
              {
            Close();

            this._keyType = keyType;

            _key = createIfDoesNotExist ? CreateSubKey(keyType, subKey) : OpenSubKey(keyType, subKey);

            this._subKey = subKey;

            return IsOpen;
              }
              catch (Exception exception)
              {
            Log.Error(exception);

            return false;
              }
        }
Ejemplo n.º 42
0
 public RegistryKey( string name )
 {
     this.Type = RegistryKeyType.Directory;
     this.Name = name;
     this.Children = new List<RegistryKey>();
 }
Ejemplo n.º 43
0
 public RegistryKey( string name, int value )
 {
     this.Type = RegistryKeyType.Integer;
     this.Name = name;
     this.ValueI = value;
 }