
正文
读写注册表 registrykey 创建删除
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
this.listBox1.Items.Clear();
RegistryKey abc = Registry.LocalMachine;
RegistryKey sub = abc.OpenSubKey(@"software",true);
RegistryKey test= sub.CreateSubKey("clp2016test");
test.SetValue("testapp","dasfdf");
foreach (string str in sub.GetSubKeyNames())
{
listBox1.Items.Add("子项名 :" + str);
RegistryKey subname = sub.OpenSubKey(str);
foreach (string sSubname in subname.GetValueNames())
{
listBox1.Items.Add(sSubname+" 值: "+subname.GetValue(sSubname));
}
} } private void button1_Click(object sender, EventArgs e)
{
this.listBox1.Items.Clear();
RegistryKey abc = Registry.LocalMachine;
RegistryKey sub = abc.OpenSubKey(@"software", true);// 权限
sub.DeleteSubKeyTree("clp2016test"); //删除
foreach (string str in sub.GetSubKeyNames())
{
listBox1.Items.Add("子项名 :" + str);
RegistryKey subname = sub.OpenSubKey(str);
foreach (string sSubname in subname.GetValueNames())
{
listBox1.Items.Add(sSubname + " 值: " + subname.GetValue(sSubname));
}
} }
}
}







