static void ReplacePowershellRibbonInternal() { using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell", true)) { //backup existing powershell config RegistryUtilities.RenameSubKey(key, "Windows.MultiVerb.Powershell", "Windows.MultiVerb.Powershell-backup"); RegistryUtilities.RenameSubKey(key, "Windows.MultiVerb.PowershellAsAdmin", "Windows.MultiVerb.PowershellAsAdmin-backup"); //copy the cmd config over to powershell RegistryUtilities.CopyKey(key, "Windows.MultiVerb.cmd", "Windows.MultiVerb.Powershell"); RegistryUtilities.CopyKey(key, "Windows.MultiVerb.cmdPromptAsAdministrator", "Windows.MultiVerb.PowershellAsAdmin"); } }
static void RestorePowershellRibbonInternal() { using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell", true)) { //check if the backup exists before doing anything var kns = key.GetSubKeyNames(); if (!kns.Contains("Windows.MultiVerb.Powershell-backup") || !kns.Contains("Windows.MultiVerb.PowershellAsAdmin-backup")) { throw new InvalidOperationException("Cannot restore powershell when backup is missing"); } key.DeleteSubKey("Windows.MultiVerb.Powershell"); key.DeleteSubKey("Windows.MultiVerb.PowershellAsAdmin"); RegistryUtilities.CopyKey(key, "Windows.MultiVerb.Powershell-backup", "Windows.MultiVerb.Powershell"); RegistryUtilities.CopyKey(key, "Windows.MultiVerb.PowershellAsAdmin-backup", "Windows.MultiVerb.PowershellAsAdmin"); } }