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);
}
}
}
关于C# 读取 写入 删除 注册表简单例子
最新推荐文章于 2022-03-29 01:23:31 发布