Esempio n. 1
0
        /// <summary>
        /// Setups the registry path.
        /// </summary>
        /// <param name="rootPath">The root path.</param>
        /// <param name="regKeyName">Name of the registry key.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <param name="environmentVariableKey">The environment variable key.</param>
        /// <returns></returns>
        protected string SetupRegistryPath(string rootPath, string regKeyName, string defaultValue,
                                           string environmentVariableKey = null)
        {
            string result;

            if (!RegistryTools.ExistsCurrentUserRoot(rootPath))
            {
                RegistryTools.CreateCurrentUserRoot(rootPath);
            }

            var keyValue = RegistryTools.GetValueCurrentUserRoot(rootPath, regKeyName);

            if (keyValue == null)
            {
                RegistryTools.SetValueCurrentUserRoot(rootPath, regKeyName, defaultValue);
                result = defaultValue;
            }
            else
            {
                result = keyValue.ToString();
            }
            if (!string.IsNullOrEmpty(environmentVariableKey))
            {
                EnvironmentVariables.Add(environmentVariableKey, result);
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets or creates a HKCU registry entry
        /// </summary>
        /// <param name="key">The key of the registry entry</param>
        /// <param name="path">The relative registry path to the entry.
        /// When <see cref="path" /> is <see langword="null" /> only the root path will be used</param>
        /// <param name="defaultValue">The value which should be used when the entry must be created</param>
        /// <returns>
        /// The value of the registry entry
        /// </returns>
        public string GetOrCreateRegistryVariable(string key, string path, string defaultValue)
        {
            var fullPath = path == null ? RegistryRootPath : Path.Combine(RegistryRootPath, path);
            var value    = RegistryTools.GetValueCurrentUserRoot(fullPath, key);

            if (value == null)
            {
                value = defaultValue;
                RegistryTools.SetValueCurrentUserRoot(fullPath, key, defaultValue);
            }

            return(value.ToString());
        }
Esempio n. 3
0
        /// <summary>
        /// Sets a HKCU registry entry
        /// </summary>
        /// <param name="key">The key of the registry entry</param>
        /// <param name="value">The value to set</param>
        /// <param name="path">The relative registry path to the entry.
        /// When <see cref="path" /> is <see langword="null" /> only the root path will be used</param>
        public void SetRegistryVariable(string key, string value, string path)
        {
            var fullPath = path == null ? RegistryRootPath : Path.Combine(RegistryRootPath, path);

            RegistryTools.SetValueCurrentUserRoot(fullPath, key, value);
        }