using Microsoft.Win32; namespace updater { internal class RegistHelper { public static string GetRegistData(RegistryKey rtype, string path, string name) { RegistryKey registryKey = rtype.OpenSubKey(path, writable: false); if (registryKey != null) { if (registryKey.GetValue(name) != null) { return registryKey.GetValue(name).ToString(); } return string.Empty; } return string.Empty; } public static string GetAllRegistData(RegistryHive rtype, string path, string name) { RegistryKey registryKey = RegistryKey.OpenBaseKey(rtype, RegistryView.Registry32).OpenSubKey(path); if (registryKey == null) { registryKey = RegistryKey.OpenBaseKey(rtype, RegistryView.Registry64).OpenSubKey(path); } if (registryKey != null) { return registryKey.GetValue(name).ToString(); } return string.Empty; } public static void WriteCURegedit(string name, string tovalue) { Registry.CurrentUser.OpenSubKey("SOFTWARE", writable: true).CreateSubKey("mine\\WordAddInTest1").SetValue(name, tovalue); } public static void DeleteCURegist(string name) { RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE", writable: true).OpenSubKey("mine\\WordAddInTest1", writable: true); string[] subKeyNames = registryKey.GetSubKeyNames(); for (int i = 0; i < subKeyNames.Length; i++) { if (subKeyNames[i] == name) { registryKey.DeleteSubKeyTree(name); } } } } }