在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
类前添加如下命名空间 using Microsoft.Win32; 添加/更新注册表: /// <summary> /// 添加注册表的值 /// </summary> /// <param name="subKey"></param> public void SaveRegistry(string subKey,string strName,string strValue) { RegistryKey regKey = Registry.CurrentUser.CreateSubKey(subKey); regKey.SetValue(strName,strValue); regKey.Close(); } 读注册表: /// <summary> /// 读取注册表 /// </summary> /// <param name="subKey"></param> /// <param name="strName"></param> /// <returns></returns> public object ReadRegistry(string subKey,string strName) { RegistryKey regKey = Registry.CurrentUser.OpenSubKey(subKey); object objtemp ; if (regKey == null) { return ""; } if(regKey.GetValue(strName) != null) { objtemp = regKey.GetValue(strName); } else { objtemp = ""; } regKey.Close(); return objtemp; } 删除注册表根节点: /// <summary> /// 删除节点 /// </summary> /// <param name="strKey"></param> public void DeleteRegistry(string strKey) { Registry.CurrentUser.DeleteSubKey(strKey); } 删除注册表的值: /// <summary> /// 删除键值 /// </summary> /// <param name="subKey"></param> /// <param name="strName"></param> public void DeleteSubRegistry(string subKey,string strName) { RegistryKey regKey = Registry.CurrentUser.CreateSubKey(subKey); regKey.DeleteValue(strName,false); } |
请发表评论