0
点赞
收藏
分享

微信扫一扫

C#编程-141:读取注册表(遍历)_彭世瑜_新浪博客

邯唐情感 2022-04-02 阅读 19


C#编程-141:读取注册表(遍历)_彭世瑜_新浪博客_winform​​



  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Microsoft.Win32;
  10. namespace RegistryTest
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. private void button1_Click(object sender, EventArgs e)
  19. {
  20. RegistryKey hklm = Registry.LocalMachine;
  21. RegistryKey software = hklm.OpenSubKey("Software");//不区分大小写
  22. RegistryKey microsoft = software.OpenSubKey("Microsoft");
  23. RegistryKey widows = microsoft.OpenSubKey("Windows");
  24. listBox1.Items.Clear();
  25. foreach (string site in widows.GetSubKeyNames())
  26. {
  27. if (site == "CurrentVersion")
  28. {
  29. RegistryKey sitekey = widows.OpenSubKey(site);
  30. foreach (string valName in sitekey.GetValueNames())
  31. {
  32. listBox1.Items.Add(valName + " : " + sitekey.GetValue(valName));
  33. }
  34. if(listBox1.Items.Count==0)
  35. MessageBox.Show("未找到相关数据");
  36. else
  37. MessageBox.Show("读取完成!");
  38. }
  39. }
  40. }
  41. }
  42. }



举报

相关推荐

0 条评论