the System the using;
the using the System.Collections.Generic;
the using the System.Text;
the using the Microsoft.Win32; // registry operation
using System.Collections; // use Arraylist
the using the System.Security.Cryptography; // encryption and decryption
using System.IO ; // file operations
using System.Runtime.InteropServices; // DllImport call DLL
a using the System.Management; // hardware information
using System.Net; // obtain an IP address is to use
a using the System.Drawing; // Image
a using System .Net.NetworkInformation; // ping used
using System.Text.RegularExpressions; // regular
a using the System.Data;
a using the System.Data.SqlClient;
a using Microsoft.VisualBasic; // use the turn Simplified Traditional
the System.Web the using; HTML UrlEncode //
// registry operations
public class GF_RegReadWrite
{
/// <Summary>
/// read path of the keypath, key named keyname registry key, the default return DEF
/// </ Summary>
/// <param name = "RootKey"> </ param>
/// <param name = "the keypath"> path </ param>
/// <param name = "KeyName"> keys </ param>
/// <param name = "RTN"> defaults to null </ param>
/// <Returns> </ Returns>
static public BOOL GetRegVal (the RegistryKey RootKey, the keypath String, String KeyName, out string rtn)
{
rtn = "";
try
{
RegistryKey key = rootkey.OpenSubKey(keypath);
rtn = key.GetValue(keyname).ToString();
key.Close();
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 设置路径为keypath,键名为keyname的注册表键值为keyval
/// </summary>
/// <param name="rootkey"></param>
/// <param name="keypath"></param>
/// <param name="keyname"></param>
/// <param name="keyval"></param>
/// <returns></returns>
static public bool SetRegVal(RegistryKey rootkey, string keypath, string keyname, string keyval)
{
try
{
RegistryKey key = rootkey.OpenSubKey(keypath, true);
if (key == null)
key = rootkey.CreateSubKey(keypath);
key.SetValue(keyname, (object)keyval);
key.Close();
return true;
}
catch
{
return false;
}
}
// create a bond path keypath
Private the RegistryKey CreateRegKey (the RegistryKey RootKey, String keypath)
{
the try
{
return rootkey.CreateSubKey (keypath);
}
the catch
{
return null;
}
}
/// Remove path keypath subkey
private bool DelRegSubKey (the RegistryKey RootKey, the keypath String)
{
the try
{
rootkey.DeleteSubKey (the keypath);
return to true;
}
the catch
{
return to false;
}
}
/// remove path for the child and its subsidiary keypath children
Private BOOL DelRegSubKeyTree (the RegistryKey RootKey, String keypath)
{
the try
{
rootkey.DeleteSubKeyTree (keypath);
return to true;
}
the catch
{
return to false ;
}
}
/// remove the path keypath key called the key keyname
private bool DelRegKeyVal(RegistryKey rootkey, string keypath, string keyname)
{
try
{
RegistryKey key = rootkey.OpenSubKey(keypath, true);
key.DeleteValue(keyname);
return true;
}
catch
{
return false;
}
}
}
the using the System.Collections.Generic;
the using the System.Text;
the using the Microsoft.Win32; // registry operation
using System.Collections; // use Arraylist
the using the System.Security.Cryptography; // encryption and decryption
using System.IO ; // file operations
using System.Runtime.InteropServices; // DllImport call DLL
a using the System.Management; // hardware information
using System.Net; // obtain an IP address is to use
a using the System.Drawing; // Image
a using System .Net.NetworkInformation; // ping used
using System.Text.RegularExpressions; // regular
a using the System.Data;
a using the System.Data.SqlClient;
a using Microsoft.VisualBasic; // use the turn Simplified Traditional
the System.Web the using; HTML UrlEncode //
// registry operations
public class GF_RegReadWrite
{
/// <Summary>
/// read path of the keypath, key named keyname registry key, the default return DEF
/// </ Summary>
/// <param name = "RootKey"> </ param>
/// <param name = "the keypath"> path </ param>
/// <param name = "KeyName"> keys </ param>
/// <param name = "RTN"> defaults to null </ param>
/// <Returns> </ Returns>
static public BOOL GetRegVal (the RegistryKey RootKey, the keypath String, String KeyName, out string rtn)
{
rtn = "";
try
{
RegistryKey key = rootkey.OpenSubKey(keypath);
rtn = key.GetValue(keyname).ToString();
key.Close();
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 设置路径为keypath,键名为keyname的注册表键值为keyval
/// </summary>
/// <param name="rootkey"></param>
/// <param name="keypath"></param>
/// <param name="keyname"></param>
/// <param name="keyval"></param>
/// <returns></returns>
static public bool SetRegVal(RegistryKey rootkey, string keypath, string keyname, string keyval)
{
try
{
RegistryKey key = rootkey.OpenSubKey(keypath, true);
if (key == null)
key = rootkey.CreateSubKey(keypath);
key.SetValue(keyname, (object)keyval);
key.Close();
return true;
}
catch
{
return false;
}
}
// create a bond path keypath
Private the RegistryKey CreateRegKey (the RegistryKey RootKey, String keypath)
{
the try
{
return rootkey.CreateSubKey (keypath);
}
the catch
{
return null;
}
}
/// Remove path keypath subkey
private bool DelRegSubKey (the RegistryKey RootKey, the keypath String)
{
the try
{
rootkey.DeleteSubKey (the keypath);
return to true;
}
the catch
{
return to false;
}
}
/// remove path for the child and its subsidiary keypath children
Private BOOL DelRegSubKeyTree (the RegistryKey RootKey, String keypath)
{
the try
{
rootkey.DeleteSubKeyTree (keypath);
return to true;
}
the catch
{
return to false ;
}
}
/// remove the path keypath key called the key keyname
private bool DelRegKeyVal(RegistryKey rootkey, string keypath, string keyname)
{
try
{
RegistryKey key = rootkey.OpenSubKey(keypath, true);
key.DeleteValue(keyname);
return true;
}
catch
{
return false;
}
}
}
Reproduced in: https: //www.cnblogs.com/kevinGao/archive/2011/11/04/2671035.html