using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
namespace Haode
{
class Regedit
{
/// <summary>
/// 读取指定名称的注册表的值
/// </summary>
/// <param name="name">注册表值</param>
/// <returns></returns>
private string GetRegistData(string name)
{
string registData;
RegistryKey hkml = Registry.LocalMachine;
RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
RegistryKey aimdir = software.OpenSubKey("China228.com", true);
registData = aimdir.GetValue(name).ToString();
return registData;
}
/// <summary>
/// 注册表中写数据
/// </summary>
/// <param name="name">注册表</param>
/// <param name="tovalue">值</param>
private void WTRegedit(string name, string tovalue)
{
RegistryKey hklm = Registry.LocalMachine;
RegistryKey software = hklm.OpenSubKey("SOFTWARE", true);
RegistryKey aimdir = software.CreateSubKey("China228.com");
aimdir.SetValue(name, tovalue);
}
/// <summary>
/// .删除注册表中指定的注册表项
/// </summary>
/// <param name="name">注册表</param>
private void DeleteRegist(string name)
{
string[] aimnames;
RegistryKey hkml = Registry.LocalMachine;
RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
RegistryKey aimdir = software.OpenSubKey("China228.com", true);
aimnames = aimdir.GetSubKeyNames();
foreach (string aimKey in aimnames)
{
if (aimKey == name)
aimdir.DeleteSubKeyTree(name);
}
}
/// <summary>
/// 判断指定注册表项是否存在
/// </summary>
/// <param name="name">注册表</param>
/// <returns></returns>
private bool IsRegeditExit(string name)
{
bool _exit = false;
string[] subkeyNames;
RegistryKey hkml = Registry.LocalMachine;
RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
RegistryKey aimdir = software.OpenSubKey("China228.com", true);
subkeyNames = aimdir.GetSubKeyNames();
foreach (string keyName in subkeyNames)
{
if (keyName == name)
{
_exit = true;
return _exit;
}
}
return _exit;
}
}
}
1 /// <summary>
2 /// 注册表基项静态域
3 ///
4 /// 主要包括:
5 /// 1.Registry.ClassesRoot 对应于HKEY_CLASSES_ROOT主键
6 /// 2.Registry.CurrentUser 对应于HKEY_CURRENT_USER主键
7 /// 3.Registry.LocalMachine 对应于 HKEY_LOCAL_MACHINE主键
8 /// 4.Registry.User 对应于 HKEY_USER主键
9 /// 5.Registry.CurrentConfig 对应于HEKY_CURRENT_CONFIG主键
10 /// 6.Registry.DynDa 对应于HKEY_DYN_DATA主键
11 /// 7.Registry.PerformanceData 对应于HKEY_PERFORMANCE_DATA主键
12 ///
13 /// 版本:1.0
14 /// </summary>
15 public enum RegDomain
16 {
17 /// <summary>
18 /// 对应于HKEY_CLASSES_ROOT主键
19 /// </summary>
20 ClassesRoot = 0,
21 /// <summary>
22 /// 对应于HKEY_CURRENT_USER主键
23 /// </summary>
24 CurrentUser = 1,
25 /// <summary>
26 /// 对应于 HKEY_LOCAL_MACHINE主键
27 /// </summary>
28 LocalMachine = 2,
29 /// <summary>
30 /// 对应于 HKEY_USER主键
31 /// </summary>
32 User = 3,
33 /// <summary>
34 /// 对应于HEKY_CURRENT_CONFIG主键
35 /// </summary>
36 CurrentConfig = 4,
37 /// <summary>
38 /// 对应于HKEY_DYN_DATA主键
39 /// </summary>
40 DynDa = 5,
41 /// <summary>
42 /// 对应于HKEY_PERFORMANCE_DATA主键
43 /// </summary>
44 PerformanceData = 6,
45 }
2.指定在注册表中存储值时所用的数据类型,或标识注册表中某个值的数据类型
1 /// <summary> 2 /// 指定在注册表中存储值时所用的数据类型,或标识注册表中某个值的数据类型 3 /// 4 /// 主要包括: 5 /// 1.RegistryValueKind.Unknown 6 /// 2.RegistryValueKind.String 7 /// 3.RegistryValueKind.ExpandString 8 /// 4.RegistryValueKind.Binary 9 /// 5.RegistryValueKind.DWord 10 /// 6.RegistryValueKind.MultiString 11 /// 7.RegistryValueKind.QWord 12 /// 13 /// 版本:1.0 14 /// </summary> 15 public enum RegValueKind 16 { 17 /// <summary> 18 /// 指示一个不受支持的注册表数据类型。例如,不支持 Microsoft Win32 API 注册表数据类型 REG_RESOURCE_LIST。使用此值指定 19 /// </summary> 20 Unknown = 0 , 21 /// <summary> 22 /// 指定一个以 Null 结尾的字符串。此值与 Win32 API 注册表数据类型 REG_SZ 等效。 23 /// </summary> 24 String = 1 , 25 /// <summary> 26 /// 指定一个以 NULL 结尾的字符串,该字符串中包含对环境变量(如 %PATH%,当值被检索时,就会展开)的未展开的引用。 27 /// 此值与 Win32 API注册表数据类型 REG_EXPAND_SZ 等效。 28 /// </summary> 29 ExpandString = 2 , 30 /// <summary> 31 /// 指定任意格式的二进制数据。此值与 Win32 API 注册表数据类型 REG_BINARY 等效。 32 /// </summary> 33 Binary = 3 , 34 /// <summary> 35 /// 指定一个 32 位二进制数。此值与 Win32 API 注册表数据类型 REG_DWORD 等效。 36 /// </summary> 37 DWord = 4 , 38 /// <summary> 39 /// 指定一个以 NULL 结尾的字符串数组,以两个空字符结束。此值与 Win32 API 注册表数据类型 REG_MULTI_SZ 等效。 40 /// </summary> 41 MultiString = 5 , 42 /// <summary> 43 /// 指定一个 64 位二进制数。此值与 Win32 API 注册表数据类型 REG_QWORD 等效。 44 /// </summary> 45 QWord = 6 , 46 }
3.注册表操作类