关于C# 读取 写入 删除 注册表简单例子

 
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 Registrykey
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void cmd_get_Click(object sender, EventArgs e)
        {
            //RegistryKey test = Registry.LocalMachine;
            //RegistryKey subkey = test.OpenSubKey("software", true);
            //RegistryKey nextsubkey = subkey.OpenSubKey("microsoft", true);
            //RegistryKey andthen = nextsubkey.OpenSubKey("windows", true);
            //RegistryKey last = andthen.OpenSubKey("currentversion", true);
            //RegistryKey end = last.OpenSubKey("webcheck", true);
            //string[] name = end.GetValueNames();
            MessageBox.Show(end.GetValue("RTHDVCPL").ToString(),"test");
            //foreach (string tes in name) {
            //    MessageBox.Show(tes,"test");
            //}
            //读取注册表测试
            RegistryKey test1 = Registry.CurrentUser;
            //RegistryKey thesubkey = test1.OpenSubKey("software\\microsoft\\windows\\currentversion\\run", true);
            RegistryKey thesubkey = test1.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
            string[] a = thesubkey.GetValueNames();
            foreach (string b in a) {
                MessageBox.Show(b,"test");
            }
        }

        private void cmd_writ_Click(object sender, EventArgs e)
        {
            //写入注册表测试
            RegistryKey test2 = Registry.CurrentUser;
            RegistryKey subkey = test2.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
            subkey.SetValue("Di", 0, RegistryValueKind.DWord);
            //禁用任务管理器
            //RegistryKey key = Registry.CurrentUser;
            //RegistryKey key1 = key.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
            //key1.SetValue("DisableTaskMgr", 0, RegistryValueKind.DWord);
        }

        private void cmd_del_Click(object sender, EventArgs e)
        {
            //删除注册表测试
            RegistryKey test3 = Registry.CurrentUser;
            RegistryKey subkey3 = test3.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",true);
            subkey3.DeleteValue("Di");
        }

        private void cmd_disablereg_Click(object sender, EventArgs e)
        {
            //禁用注册表测试
            RegistryKey test4 = Registry.CurrentUser;
            RegistryKey subkey4 = test4.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
            subkey4.SetValue("DisableRegistryTools", 1, RegistryValueKind.DWord);
        }

        private void cmd_back_Click(object sender, EventArgs e)
        {
            //恢复注册表可用测试
            RegistryKey test5 =  Registry.CurrentUser;
            RegistryKey subkey5 = test5.OpenSubKey("software\\microsoft\\windows\\currentversion\\policies\\system", true);
            subkey5.SetValue("DisableRegistryTools", 0, RegistryValueKind.DWord);
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值