注册表读取和写入

static void Main(string[] args)
{
RegistryKey regkey = Registry.CurrentUser.OpenSubKey("cc");
if (regkey != null)
{
Console.WriteLine(regkey.GetValue("UserName").ToString());//读取注册表
regkey.Close();
}
Console.ReadKey();
}
//创建和写入注册表
private static void Test()
{
RegistryKey regkey = Registry.CurrentUser.CreateSubKey("cc");//"cc"要取一个特殊的字符串,防止与系统或其他程序写注册表名称相同,
            regkey.SetValue("UserName", "cwx776534");
regkey.Close();
}

猜你喜欢

转载自www.cnblogs.com/zhujie-com/p/12190115.html