- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using Microsoft.Win32;
- namespace RegistryTest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- RegistryKey hklm = Registry.LocalMachine;
- RegistryKey software = hklm.OpenSubKey("Software");//不区分大小写
- RegistryKey microsoft = software.OpenSubKey("Microsoft");
- RegistryKey widows = microsoft.OpenSubKey("Windows");
- listBox1.Items.Clear();
- foreach (string site in widows.GetSubKeyNames())
- {
- if (site == "CurrentVersion")
- {
- RegistryKey sitekey = widows.OpenSubKey(site);
- foreach (string valName in sitekey.GetValueNames())
- {
- listBox1.Items.Add(valName + " : " + sitekey.GetValue(valName));
- }
- if(listBox1.Items.Count==0)
- MessageBox.Show("未找到相关数据");
- else
- MessageBox.Show("读取完成!");
- }
- }
- }
- }
- }
C#编程-141:读取注册表(遍历)
最新推荐文章于 2024-08-12 08:00:00 发布