C#编程-142:新增注册表
2024-06-25 09:50:39 阅读次数:43
编程开发
- 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);
- }
- }
- }
- }
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/mouday/3047206,作者:彭世瑜,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。
上一篇:Python编程:calendar日历模块入门
下一篇:C#编程-99:索引器实例QQ状态