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);
}
}
}
}