- using System;
- using System.Windows.Forms;
- using Microsoft.Win32;
- namespace RegistryTestSetValue
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void btnSetup_Click(object sender, EventArgs e)
- {
- if (txtKey.Text == "") {
- MessageBox.Show("输入错误");
- return ;}
- RegistryKey hklm = Registry.LocalMachine;
- RegistryKey sys = hklm.OpenSubKey("System",true);
- RegistryKey temp = sys.CreateSubKey(txtKey.Text);
- temp.SetValue(txtName.Text,txtValue.Text);
- //listBox1.Items.Clear();
- foreach (string site in sys.GetSubKeyNames())
- {
- if (txtKey.Text == site)
- {
- RegistryKey sitekey = sys.OpenSubKey(site);
- foreach (string svalue in sitekey.GetSubKeyNames())
- {
- listBox1.Items.Add(sitekey+svalue + " : " + sitekey.GetValue(svalue));
- }
- }
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- RegistryKey hklm = Registry.LocalMachine;
- RegistryKey sys = hklm.OpenSubKey("System");
- listBox1.Items.Clear();
- foreach (string subkey in sys.GetSubKeyNames())
- {
- listBox1.Items.Add(subkey);
- }
- }
- }
- }
C#编程-142:新增注册表
最新推荐文章于 2021-03-02 22:48:42 发布