请问怎么样用C#遍厉注册表?

swhrc 2003-06-07 11:21:11
请各位高手帮帮!!!
...全文
20 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
AngelGavin 2003-06-12
  • 打赏
  • 举报
回复
using System;
using Microsoft.Win32;
namespace test
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
Class1 test=new Class1();
test.getreg(Registry.LocalMachine,"");
test.getreg(Registry.ClassesRoot,"");
test.getreg(Registry.CurrentConfig,"");
test.getreg(Registry.CurrentUser,"");
test.getreg(Registry.Users);
}
public void getreg(RegistryKey root,string key)
{
RegistryKey nowkey=root;
try
{
if(key!="")
{
nowkey=nowkey.OpenSubKey(key);
}
Console.WriteLine("Open "+root.ToString()+"\\"+key);
foreach(string tempname in nowkey.GetValueNames())
{
Console.WriteLine(" "+tempname+" = "+nowkey.GetValue(tempname).ToString());
}
foreach(string tempsubkey in nowkey.GetSubKeyNames())
{
this.getreg(nowkey,tempsubkey);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
lovered 2003-06-08
  • 打赏
  • 举报
回复
[v]
liduke 2003-06-08
  • 打赏
  • 举报
回复
用递归,遍历所有鍵,查询下面的值
youngby 2003-06-08
  • 打赏
  • 举报
回复
guai hao
jinus 2003-06-08
  • 打赏
  • 举报
回复
用递归函数,就像遍历目录一样。
coollzh 2003-06-07
  • 打赏
  • 举报
回复
RegistryKey hklm = Registry.LocalMachine ;
RegistryKey software = hklm.OpenSubKey ( "SOFTWARE" ) ;
//打开"SOFTWARE"子键
RegistryKey no1 = software.OpenSubKey ( "aaa" ) ;
//打开"aaa"子键
foreach ( string site in no1.GetSubKeyNames ( ) )
//开始遍历由子键名称组成的字符串数组
{
listBox1.Items.Add ( site ) ;
//在列表中加入子键名称
RegistryKey sitekey = no1.OpenSubKey ( site ) ;
//打开此子键
foreach ( string sValName in sitekey.GetValueNames ( ) )
//开始遍历由指定子键拥有的键值名称组成的字符串数组
{
listBox1.Items.Add ( " " + sValName + ": " + sitekey.GetValue ( sValName ) ) ;
//在列表中加入键名称和对应的键值
}
}

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧