关闭

读取注册表键值

743人阅读 评论(0) 收藏 举报

/// 读取注册表键值
/// </summary>
public static string ReadRegistryKey(string name)
{
Microsoft.Win32.RegistryKey reg = Microsoft.Win32.Registry.CurrentUser;
string path="Software//" + Application.ProductName;

if (reg.OpenSubKey(path) == null)
reg.CreateSubKey(path);

reg = reg.OpenSubKey(path, true);

string str;
if (reg.GetValue(name) == null)
str="";
else
    str = reg.GetValue(name).ToString();

reg.Close();
return str;
}

/// <summary>
/// 设置注册表键值
/// </summary>
public static void SetRegistryKey(string name, string Value)
{
Microsoft.Win32.RegistryKey reg = Microsoft.Win32.Registry.CurrentUser;
string path="Software//" + Application.ProductName;

if (reg.OpenSubKey(path) == null)
reg.CreateSubKey(path);

reg=reg.OpenSubKey(path,true);

reg.SetValue(name, Value);
reg.Close();
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:138972次
    • 积分:1922
    • 等级:
    • 排名:千里之外
    • 原创:38篇
    • 转载:56篇
    • 译文:2篇
    • 评论:12条
    文章分类