您的位置:首页 > 其它

读写注册表的封装

2009-04-07 07:45 387 查看
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace WriteInReg
{
public class WriteIntoReg
{
/// <summary>
/// 从注册表获取值
/// </summary>
/// <param name="strKey">键值</param>
/// <returns></returns>
public static string GetValueRegUserKey(string strKey)
{
string strValue = "";
try
{
string str = string.Format(@"SoftWare/FreshAir/" + strKey);
RegistryKey Reg = Registry.CurrentUser.CreateSubKey(str);
Reg = Registry.CurrentUser.OpenSubKey(str);
strValue = Reg.GetValue("UserKey", "Admin").ToString();
Reg.Close();
}
catch { }
return strValue;
}
/// <summary>
/// 保存到注册表
/// </summary>
/// <param name="strKey">键</param>
/// <param name="strValue">值</param>
public static void SavaValueRegUserKey(string strKey, string strValue)
{
try
{
string str = string.Format(@"SoftWare/FreshAir/" + strKey);
RegistryKey Reg = Registry.CurrentUser.CreateSubKey(str);
Reg.SetValue("UserKey", strValue);
Reg.Close();
}
catch { }
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: