public async Task OpenRegistryKeyAsync(string registryKeyPath) { if (!RegistryHelpers.KeyExists(registryKeyPath)) { await Message.DisplayMessageAsync(Resources.File_RegKeyNotFound, Resources.File_RegKeyNotFoundHeader, MessageType.Error); return; } try { WindowsHelpers.OpenRegistryPath(registryKeyPath); Logger.Debug("The Registry key path {0} was opened", registryKeyPath); } catch (Exception ex) { Logger.Error(ex, "Opening Registry key path {0}", registryKeyPath); await Message.DisplayExceptionMessageAsync(ex, Resources.File_OpenRegKeyError, Resources.File_OpenRegKeyErrorHeader); } }
/// <summary> /// Renames the specified sub key /// </summary> /// <param name="registryKey">The parent registry key</param> /// <param name="subKeyName">The name of the sub key to rename</param> /// <param name="newSubKeyName">The new name of the key</param> public static void MoveSubKey(this RegistryKey registryKey, string subKeyName, string newSubKeyName) { // Make sure the new name doesn't exist if (RegistryHelpers.KeyExists(RegistryHelpers.CombinePaths(registryKey.Name, newSubKeyName), registryKey.View)) { throw new Exception($"The key {newSubKeyName} already exists"); } // Make sure the original key exists if (!RegistryHelpers.KeyExists(RegistryHelpers.CombinePaths(registryKey.Name, subKeyName), registryKey.View)) { throw new Exception($"The key {subKeyName} does not exist"); } try { // Copy the key registryKey.CopySubKey(subKeyName, newSubKeyName); } catch (Exception ex) { // Delete copied key registryKey.DeleteSubKeyTree(newSubKeyName, false); throw new Exception("Failed to copy sub key tree. Operation failed.", ex); } try { // Delete the old key registryKey.DeleteSubKeyTree(subKeyName); } catch (Exception ex) { throw new Exception("Failed to fully delete old key", ex); } }