diff --git a/OldContextMenu/Program.cs b/OldContextMenu/Program.cs index 790481d..e9eca06 100644 --- a/OldContextMenu/Program.cs +++ b/OldContextMenu/Program.cs @@ -1,67 +1,78 @@ using Microsoft.Win32; using System.Diagnostics; -Console.WriteLine("Let's change the context menu!"); - - +const string regKey = @"Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"; -//RegistryKey exist = Registry.CurrentUser.Name; - -RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"); +Console.WriteLine("Let's change the context menu!"); +RegistryKey key = Registry.CurrentUser.OpenSubKey(regKey); -if (key != null) -{ +if (key == null) OldContext(); - - Console.WriteLine(""); -} else -{ NewContext(); - Console.WriteLine(""); -} +Console.WriteLine(@"Press any key to finish..."); Console.ReadKey(); - - -// HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32 - - - static void OldContext() { - try { - Console.WriteLine(@"Creating subkey HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"); - RegistryKey keyIn = Registry.CurrentUser.CreateSubKey(@"Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"); + Console.WriteLine("New context menu ---> Old context menu"); + Console.WriteLine($"Creating subkey {regKey}"); + + RegistryKey keyIn = Registry.CurrentUser.CreateSubKey(regKey); - //Adds the "(Default)" value and sets data to "" instead of "not defined" keyIn.SetValue("", ""); keyIn.Close(); + + + //Gets all processes with "explorer" as name. Since there probably is only one. Is there a GetProcessByName? probably + Process[] explorer = Process.GetProcessesByName("explorer"); + + //kills Explorer.exe since needed for the context menu to update + explorer[0].Kill(); + + Process process = new Process(); + process.StartInfo.FileName = "explorer"; + process.StartInfo.UseShellExecute = true; + process.Start(); + + Console.WriteLine("Added registry key to get the old context menu back. Try right-clicking a file!"); } catch (Exception ex) { Console.WriteLine(ex); } +} - //Gets all processes with "explorer" as name. Since there probably is only one. Is there a GetProcessByName? probably - Process[] explorer = Process.GetProcessesByName("explorer"); +static void NewContext() +{ + try + { + Console.WriteLine("Old context menu ---> new context menu"); + Console.WriteLine($"Deleting subkey {regKey}"); - //kills Explorer.exe since needed for the context menu to update - explorer[0].Kill(); + Registry.CurrentUser.DeleteSubKey(regKey); + Registry.CurrentUser.DeleteSubKey(regKey.Remove(regKey.Length - 15)); + - Process process = new Process(); - process.StartInfo.FileName = "explorer"; - process.StartInfo.UseShellExecute = true; - process.Start(); + //Gets all processes with "explorer" as name. Since there probably is only one. Is there a GetProcessByName? probably + Process[] explorer = Process.GetProcessesByName("explorer"); - Console.WriteLine("Added registry key to get the old context menu back. Try right-clicking a file!"); -} + //kills Explorer.exe since needed for the context menu to update + explorer[0].Kill(); -static void NewContext() -{ + Process process = new Process(); + process.StartInfo.FileName = "explorer"; + process.StartInfo.UseShellExecute = true; + process.Start(); + Console.WriteLine("Deleted registry key to get the new context menu back. Try right-clicking a file!"); + } + catch (Exception ex) + { + Console.WriteLine(ex); + } } \ No newline at end of file