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);
--=阅读快乐=--
欢迎访问我的新鱼塘 www.pumaboyd.com