Esempio n. 1
0
        /// <summary>
        /// Sets one value in the registry.
        /// </summary>
        /// <param name="root">The root key to set the value under.</param>
        /// <param name="name">The path to the value to set.</param>
        /// <param name="value">The value to set.</param>
        /// <returns>Returns true if the value is set, false otherwise.</returns>
        private static bool SetValue(RegistryKey root, string name, object value)
        {
            Param.AssertNotNull(root, "root");
            Param.AssertValidString(name, "name");
            Param.AssertNotNull(value, "value");

            try
            {
                PathInfo pathinfo = RegistryUtils.CreatePath(root, name);
                if (pathinfo.Key == null)
                {
                    return(false);
                }
                else
                {
                    pathinfo.Key.SetValue(pathinfo.Stub, value);
                }

                return(true);
            }
            catch (ArgumentException)
            {
            }
            catch (IOException)
            {
            }
            catch (UnauthorizedAccessException)
            {
            }
            catch (SecurityException)
            {
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds one key to the registry under the given root node.
        /// </summary>
        /// <param name="root">The root node that the key should be added under.</param>
        /// <param name="name">The path to the key to add.</param>
        /// <returns>Returns the new key if it was added, or null if it could not be added.</returns>
        private static RegistryKey AddKey(RegistryKey root, string name)
        {
            Param.AssertNotNull(root, "root");
            Param.AssertValidString(name, "name");

            try
            {
                PathInfo pathinfo = RegistryUtils.CreatePath(root, name);
                if (pathinfo.Key == null)
                {
                    return(null);
                }
                else
                {
                    return(pathinfo.Key.CreateSubKey(pathinfo.Stub));
                }
            }
            catch (SecurityException)
            {
            }
            catch (ArgumentException)
            {
            }
            catch (IOException)
            {
            }
            catch (UnauthorizedAccessException)
            {
            }

            return(null);
        }