RegisterTool.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Microsoft.Win32;
  2. using System;
  3. namespace Y.Utils.Net20.ComputerUtils
  4. {
  5. public class RegisterTool
  6. {
  7. /// <summary>
  8. /// 写入注册表项
  9. /// </summary>
  10. /// <param name="key">SOFTWARE\\NC_VideoConferenceSystem</param>
  11. /// <param name="name">RegTime</param>
  12. /// <param name="value">yyyy-MM-dd hh:mm:ss</param>
  13. public static bool Write(string key, string name, string value)
  14. {
  15. try
  16. {
  17. RegistryKey RKey = Registry.LocalMachine.OpenSubKey(key, true);
  18. if (RKey == null)
  19. RKey = Registry.LocalMachine.CreateSubKey(key);
  20. RKey.SetValue(name, value);
  21. return true;
  22. }
  23. catch (Exception e)
  24. {
  25. return false;
  26. }
  27. }
  28. /// <summary>
  29. /// 读取注册表项
  30. /// </summary>
  31. /// <param name="key">SOFTWARE\\NC_VideoConferenceSystem</param>
  32. /// <param name="name">Path</param>
  33. /// <returns></returns>
  34. public static string Read(string key, string name)
  35. {
  36. try
  37. {
  38. RegistryKey RKey = Registry.LocalMachine.OpenSubKey(key, true);
  39. if (RKey != null)
  40. {
  41. return RKey.GetValue(name) != null ? RKey.GetValue(name).ToString() : "";
  42. }
  43. }
  44. catch (Exception e) { }
  45. return null;
  46. }
  47. public static bool Delete(string key, string name)
  48. {
  49. try
  50. {
  51. RegistryKey RKey = Registry.LocalMachine.OpenSubKey(key, true);
  52. if (RKey != null && RKey.GetValue(name) != null)
  53. RKey.DeleteValue(name);
  54. return true;
  55. }
  56. catch (Exception e)
  57. {
  58. return false;
  59. }
  60. }
  61. }
  62. }