コード例 #1
0
ファイル: RegistryEditor.cs プロジェクト: Bloodimir/Projects
        public static bool DeleteRegistryValue(string keyPath, string name, out string errorMsg)
        {
            try
            {
                RegistryKey key = GetWritableRegistryKey(keyPath);

                if (key == null)
                {
                    errorMsg = "Bu kayıdı açmak için izniniz yoktur: " + keyPath +
                               ", clientin yönetici olarak çalıştırılması gerekiyor.";
                    return(false);
                }

                if (!key.ContainsValue(name))
                {
                    errorMsg = "Değer: " + name + " bu dizinde bulunmamaktadır: " + keyPath;
                    return(true);
                }

                bool success = key.DeleteValueSafe(name);
                if (!success)
                {
                    errorMsg = REGISTRY_VALUE_DELETE_ERROR;
                    return(false);
                }

                errorMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
                return(false);
            }
        }
コード例 #2
0
 public static bool RenameValueSafe(this RegistryKey key, string oldName, string newName)
 {
     try
     {
         key.CopyValue(oldName, newName);
         key.DeleteValue(oldName);
         return(true);
     }
     catch
     {
         key.DeleteValueSafe(newName);
         return(false);
     }
 }
コード例 #3
0
 /// <summary>
 /// Attempts to rename a registry value to the key provided using the specified old
 /// name and new name.
 /// </summary>
 /// <param name="key">The key of which the registry value is to be renamed from.</param>
 /// <param name="oldName">The old name of the registry value.</param>
 /// <param name="newName">The new name of the registry value.</param>
 /// <returns>Returns boolean value if the action succeded or failed; Returns
 /// </returns>
 public static bool RenameValueSafe(this RegistryKey key, string oldName, string newName)
 {
     try
     {
         //Copy from old to new
         key.CopyValue(oldName, newName);
         //Despose of the old value
         key.DeleteValue(oldName);
         return(true);
     }
     catch
     {
         //Try to despose of the newKey (The rename failed)
         key.DeleteValueSafe(newName);
         return(false);
     }
 }
コード例 #4
0
        /// <summary>
        /// Attempts to delete the desired registry value from the specified key.
        /// </summary>
        /// <param name="keyPath">The path to the key for which to delete the registry value on.</param>
        /// /// <param name="name">The name of the registry value to delete.</param>
        /// <param name="errorMsg">output parameter that contians possible error message.</param>
        /// <returns>Returns true if the operation succeeded.</returns>
        public static bool DeleteRegistryValue(string keyPath, string name, out string errorMsg)
        {
            try
            {
                RegistryKey key = GetWritableRegistryKey(keyPath);

                //Invalid can not open key
                if (key == null)
                {
                    errorMsg = "You do not have write access to registry: " + keyPath + ", try running client as administrator";
                    return(false);
                }

                //Value does not exist
                if (!key.ContainsValue(name))
                {
                    errorMsg = "The value: " + name + " does not exist in: " + keyPath;
                    //If value does not exists then the action has already succeeded
                    return(true);
                }

                bool success = key.DeleteValueSafe(name);

                //Value could not be deleted
                if (!success)
                {
                    errorMsg = REGISTRY_VALUE_DELETE_ERROR;
                    return(false);
                }

                //Value was successfully deleted
                errorMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
                return(false);
            }
        }