在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
c# 简单读写注册表 1 /// <summary> 2 /// 注册表 3 /// </summary> 4 public class Regedit 5 { 6 private const string SUB_KEY = "SOFTWARE"; 7 private static readonly RegistryKey HKML; 8 private static readonly RegistryKey SOFTWARE; 9 10 static Regedit() 11 { 12 //Win10 读写LocalMachine权限,没有访问权限 13 HKML = Registry.CurrentUser; 14 SOFTWARE = HKML.OpenSubKey(SUB_KEY, true); 15 } 16 17 /// <summary> 18 /// 读取数据 19 /// </summary> 20 /// <param name="node">节点</param> 21 /// <param name="name">名称</param> 22 /// <returns></returns> 23 public static object GetData(string node, string name) 24 { 25 RegistryKey tmp = SOFTWARE.OpenSubKey(node, true); 26 return tmp?.GetValue(name); 27 } 28 29 /// <summary> 30 /// 写入值 31 /// </summary> 32 /// <param name="node">节点</param> 33 /// <param name="name">名称</param> 34 /// <param name="value">值</param> 35 public static void AddItem(string node, string name, object value) 36 { 37 RegistryKey tmp = SOFTWARE.CreateSubKey(node); 38 tmp?.SetValue(name, value); 39 } 40 }
|
请发表评论