您的位置:首页 > 编程语言 > C#

C#读取和写入注册表

2014-06-05 18:09 281 查看
RegistryKey hklm = Microsoft.Win32.Registry.LocalMachine;

RegistryKey hkSoftware = hklm.OpenSubKey("Software");

//只读

//RegistryKey hkMicrosoft = hkSoftware.OpenSubKey("Microsoft");

//可以写入

RegistryKey hkMicrosoft = hkSoftware.OpenSubKey("Microsoft",true);

//如果这个键以及存在,则返回RegistryKey事例,否则创建这个键

RegistryKey hkkey = hkMicrosoft.CreateSubKey("demo");

//写入

hkkey.SetValue("StringValue", "hello");

hkkey.SetValue("IntValue", 20);

//读取

string stringValue = hkkey.GetValue("StringValue").ToString();

int intValue = Convert.ToInt32(hkkey.GetValue("IntValue"));

//完成读取或者修改数据后,关闭键

hkkey.Close();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: