static void Main(string[] args) { string registrypath = null; try { // Asks user to enter the path that will locate the addins in hKey Current User Console.WriteLine("Enter the path to the addins: "); registrypath = Console.ReadLine(); } catch (ArgumentException e) { Console.WriteLine("The path entered is invalid."); } MIORegKeyManager obj = new MIORegKeyManager(); RegistryKey currentuser64 = null; RegistryKey rootfile = null; try {// Opens a new RegistryKey that represents the path on the local machine with the specified view currentuser64 = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64); //Console.WriteLine(currentuser64); } catch (ArgumentException e) { Console.WriteLine("The hKey or view is invalid."); Environment.Exit(1); } try { // Retrieves the subkey as read-only rootfile = currentuser64.OpenSubKey(registrypath, true); //Console.WriteLine(rootfile); } catch (ObjectDisposedException e) { Console.WriteLine("The RegistryKey is closed."); Environment.Exit(1); } catch (ArgumentNullException e) { Console.WriteLine("The requested subkey is null."); Environment.Exit(1); } // Sets the values of the disabled addins obj.SetValues(rootfile, obj.GetNames(rootfile)); Console.ReadLine(); }
static void Main(string[] args) { // Path that locates the addins string registrypath = "Software\\Microsoft\\Office\\14.0\\Excel\\Options"; MIORegKeyManager obj = new MIORegKeyManager(); RegistryKey currentuser64 = null; RegistryKey rootfile = null; try {// Opens a new RegistryKey that represents the path on the local machine with the specified view currentuser64 = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64); //Console.WriteLine(currentuser64); } catch (ArgumentException e) { Console.WriteLine("The hKey or view is invalid. Stacktrace:" + e.Message); Environment.Exit(1); // throw new Exception("The hKey or view is invalid. Stacktrace:"+e.Message); } try { // Retrieves the subkey as read-only rootfile = currentuser64.OpenSubKey(registrypath, true); //Console.WriteLine(rootfile); } catch (ObjectDisposedException e) { Console.WriteLine("The RegistryKey is closed."); Environment.Exit(1); } catch (ArgumentNullException e) { Console.WriteLine("The requested subkey is null."); Environment.Exit(1); } // Sets the values of the disabled addins obj.SetValues(rootfile, obj.GetNames(rootfile)); Console.WriteLine(rootfile); //Console.ReadLine(); Environment.Exit(0); }