using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Drawing;
using
System.Data;
using
System.Text;
using
System.Windows.Forms;
using
System.Data.SqlClient;
using
Microsoft.Win32;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
namespace
WindowsForm
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
...
{
public partial class doits : UserControl
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
private RegistryKey hkml;
private DataSet ds = new DataSet();
private string MenuName;
public string StringName
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
set
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
MenuName = value;
}
}
public doits()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
InitializeComponent();
}
private void doits_Load(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
if (MenuName != null)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
//this.button1.Text = MenuName;
create();
}
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
// this.button1.Text = "没有任何操作";
label1.Text = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
toolStripStatusLabel1.Text = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
this.label2.Text = "程序制作说明:";
this.richTextBox1.Text = "程序说明文件,自己写";
this.button1.Visible = false;
this.button2.Visible = false;
}
}
private void create()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
SqlDataAdapter ad = new SqlDataAdapter("select * from operator where MenuID=" + MenuName + ";select * from Menu where ID=" + MenuName, "server=.;uid=sa;pwd=;database=Data");
ad.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
this.label1.Text = "数据库优化名称为:" + ds.Tables[1].Rows[0]["MenuText"].ToString();
toolStripStatusLabel1.Text = ds.Tables[1].Rows[0]["MenuText"].ToString();
this.richTextBox1.Text = ds.Tables[0].Rows[0]["Description"].ToString();
}
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
this.button1.Enabled = false;
this.button2.Enabled = false;
label1.Text = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
toolStripStatusLabel1.Text = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
this.label2.Text = "程序制作说明:";
this.richTextBox1.Text = "程序说明文件,自己写";
MessageBox.Show("我日,没有要修改的数据","操",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void button1_Click(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
//打开数据库,更加传进来的参数,对数据库进行一步步优化操作,及注册表的增删改等等操作。
foreach (DataRow dr in ds.Tables[0].Rows)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
if (dr["operator"].ToString() == "添加")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
string path = dr["Address"].ToString();
string name = dr["opName"].ToString();
object tovalue = dr["opNewValue"].ToString();
RegistryValueKind Kind;
if (dr["opType"].ToString() == "Binary")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind = RegistryValueKind.Binary;
}
else if (dr["opType"].ToString() == "DWord")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind = RegistryValueKind.DWord;
}
else if (dr["opType"].ToString() == "ExpandString")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind = RegistryValueKind.ExpandString;
}
else if (dr["opType"].ToString() == "MultiString")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind = RegistryValueKind.MultiString;
}
else if (dr["opType"].ToString() == "QWord")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind=RegistryValueKind.QWord;
}
else if (dr["opType"].ToString() == "String")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind=RegistryValueKind.String;
}
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind=RegistryValueKind.Unknown;
}
WTRegedit(path,name,tovalue,Kind);
}
else if (dr["operator"].ToString() == "修改")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
string path = dr["Address"].ToString();
string name = dr["opName"].ToString();
object tovalue = dr["opNewValue"].ToString();
ChangeRegedit(path, name, tovalue);
}
else if (dr["operator"].ToString() == "删除")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
string path = dr["Address"].ToString();
string name = dr["opName"].ToString();
dRegedit(path, name);
}
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
MessageBox.Show("他妈的,我不能处理了!你数据库怎么录入的。");
}
}
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void button2_Click(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
foreach (DataRow dr in ds.Tables[0].Rows)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
if (dr["operator"].ToString() == "添加")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
string path = dr["Address"].ToString();
string name = dr["opName"].ToString();
dRegedit(path, name);
}
else if (dr["operator"].ToString() == "修改")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
string path = dr["Address"].ToString();
string name = dr["opName"].ToString();
object tovalue = dr["opOleValue"].ToString();
ChangeRegedit(path, name, tovalue);
}
else if (dr["operator"].ToString() == "删除")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
string path = dr["Address"].ToString();
string name = dr["opName"].ToString();
object tovalue = dr["opOleValue"].ToString();
RegistryValueKind Kind;
if (dr["opType"].ToString() == "Binary")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind = RegistryValueKind.Binary;
}
else if (dr["opType"].ToString() == "DWord")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind = RegistryValueKind.DWord;
}
else if (dr["opType"].ToString() == "ExpandString")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind = RegistryValueKind.ExpandString;
}
else if (dr["opType"].ToString() == "MultiString")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind = RegistryValueKind.MultiString;
}
else if (dr["opType"].ToString() == "QWord")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind = RegistryValueKind.QWord;
}
else if (dr["opType"].ToString() == "String")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind = RegistryValueKind.String;
}
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Kind = RegistryValueKind.Unknown;
}
WTRegedit(path, name, tovalue, Kind);
}
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
MessageBox.Show("他妈的,我不能处理了!你数据库怎么录入的。");
}
}
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private RegistryKey setKey(string path)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
string[] a = path.Split('\');
if (path.Substring(0, a[0].Length) == "HKEY_CLASSES_ROOT")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
hkml = Registry.ClassesRoot;
}
else if (path.Substring(0, a[0].Length) == "HKEY_CURRENT_USER")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
hkml = Registry.CurrentUser;
}
else if (path.Substring(0, a[0].Length) == "HKEY_LOCAL_MACHINE")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
hkml = Registry.LocalMachine;
}
else if (path.Substring(0, a[0].Length) == "HKEY_USERS")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
hkml = Registry.Users;
}
else if (path.Substring(0, a[0].Length) == "HKEY_CURRENT_CONFIG")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
hkml = Registry.CurrentConfig;
}
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
hkml = null;
}
return hkml;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public string GetRegeditData(string path, string name)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
string[] aimnames;
string keyData = string.Empty;
hkml = setKey(path).OpenSubKey(path.Substring(hkml.Name.Length + 1), true);
aimnames = hkml.GetValueNames();
foreach (string aimKey in aimnames)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
if (aimKey == name)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
keyData = hkml.GetValue(name).ToString();
}
}
return keyData;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//向注册表中写人数据
public void WTRegedit(string path, string name, object tovalue, RegistryValueKind Kind)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
hkml = setKey(path).CreateSubKey(path.Substring(hkml.Name.Length + 1));
hkml.SetValue(name, tovalue, Kind);
}
public void ChangeRegedit(string path, string name, object tovalue)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
hkml = setKey(path).CreateSubKey(path.Substring(hkml.Name.Length + 1));
hkml.SetValue(name, tovalue);
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void dRegedit(string path, string name)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
string[] aimnames;
hkml = setKey(path).OpenSubKey(path.Substring(hkml.Name.Length + 1), true);
aimnames = hkml.GetValueNames();
foreach (string aimKey in aimnames)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
if (aimKey == name)
hkml.DeleteValue(name);
}
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void DeleteRegist(string path, string name)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
string[] aimnames;
hkml = setKey(path).OpenSubKey(path.Substring(hkml.Name.Length + 1), true);
aimnames = hkml.GetSubKeyNames();
foreach (string aimKey in aimnames)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
if (aimKey == name)
hkml.DeleteSubKey(name);
}
}
}
}
转载于:https://www.cnblogs.com/wkjs/archive/2007/06/29/2008533.html