繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> C#语言 >> 在C#中操作注册表

在C#中操作注册表

2004-10-01 08:26:10  作者:  来源:互联网  浏览次数:64  文字大小:【】【】【
简介:使用VC,VB等语言操作注册表的例子已经有很多了,其实在C#里操作注册表更加的简单方便。下面的例子就提供了在C#里操作注册表的方法: using Microsoft.Win32; using System.Diagnostics; private voi...
关键字:C# 注册表

使用VC,VB等语言操作注册表的例子已经有很多了,其实在C#里操作注册表更加的简单方便。下面的例子就提供了在C#里操作注册表的方法:

using Microsoft.Win32;

using System.Diagnostics;

private void Access_Registry()

{

// 在HKEY_LOCAL_MACHINE\Software下建立一新键,起名为MCBInc

RegistryKey key = Registry.LocalMachine.OpenSubKey("Software", true);

// 增加一个子键

RegistryKey newkey = key.CreateSubKey("MCBInc");

// 设置此子键的值

newkey.SetValue("MCBInc", "NET Developer");

// 从注册表的其他地方获取数据

// 找出你的CPU

RegistryKey pRegKey = Registry.LocalMachine;

pRegKey = pRegKey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");

Object val = pRegKey.GetValue("VendorIdentifier");

Debug.WriteLine("The central processor of this machine is:"+ val);

// 删除键值

RegistryKey delKey = Registry.LocalMachine.OpenSubKey("Software", true);

delKey.DeleteSubKey("MCBInc");

}

责任编辑:admin
相关文章