C#操作注册表
//创建注册表下并加载信息。 public bool registryCreateAndSet(string FillName, string Name, string Value) { try { //引用HKEY_CURRENT_USER RegistryKey key = Registry.CurrentUser; //在HKEY_CURRENT_USER里面的SOFTWARE创建registryForFeSoftOfGYN\TouchScreen,在这个文件夹下创建一系列的文件 RegistryKey MyRegistry = key.CreateSubKey(@"SOFTWARE\ExcelDigit\Excel\" + FillName); MyRegistry.SetValue(Name, Value); } catch (Exception m) { return false; } return true; } //读取注册表中指定文件的信息, public bool registryRead(string FillName, string Name, out string Value) { try { RegistryKey key = Registry.CurrentUser;//找到HKEY_CURRENT_USER //在HKEY_CURRENT_USER下,找SOFTWARE\ExcelDigit\Excel\FillName RegistryKey MyRegistry = key.OpenSubKey(@"SOFTWARE\ExcelDigit\Excel\" + FillName); if (MyRegistry == null) { //NameV = null; Value = null; return false; } //在HKEY_CURRENT_USER\SOFTWARE\ExcelDigit\Excel\ FillName下读取Name 信息。 // NameV = MyRegistry.GetValue(NameV).ToString(); Value = MyRegistry.GetValue(Name).ToString(); } catch (Exception) { Value = null; //NameV = null; return false; } return true; }
读取与写入
1) RegistryOperation RegistryFuntion = new RegistryOperation(); string url = ""; RegistryFuntion.registryRead("Login", "url", out url); 2) RegistryFuntion.registryCreateAndSet("Login", "url", url);
,Best Wish 不负年华