在C#中操作注册表

王朝c#·作者佚名  2006-01-08
宽屏版  字体: |||超大  

作者:杨忠勋

专业:计算机软件开发及应用

语言能力:TOFEL633 GRE2140

Email:zhongxunyang@yahoo.com.cn

使用 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"); }

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有