Using system;
Using system. Collections. Generic;
Using system. text;
Using Microsoft. Win32; // perform registry operations
Using system. collections; // use arraylist
Using system. Security. cryptography; // encryption and decryption
Using system. IO; // File Operations
Using system. runtime. interopservices; // Call DLL dllimport
Using system. Management; // obtain hardware information
Using system. Net; // used to obtain the IP address
Using system. Drawing; // Image
Using system. net. networkinformation; // used for Ping
Using system. Text. regularexpressions; // regular
Using system. Data;
Using system. Data. sqlclient;
Using Microsoft. VisualBasic; // used in simplified to traditional Chinese
Using system. Web; // html urlencode
// Registry operation
Public class gf_regreadwrite
{
/// <Summary>
/// The read path is keypath and the key name is the key value of the registry. Def is returned by default.
/// </Summary>
/// <Param name = "rootkey"> </param>
/// <Param name = "keypath"> path </param>
/// <Param name = "keyname"> key name </param>
/// <Param name = "RTN"> default value: NULL </param>
/// <Returns> </returns>
Static public bool getregval (registrykey rootkey, string keypath, 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>
/// Set the path to keypath and the registry key with the key name keyname to 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;
}
}
/// Key whose path is keypath
Private registrykey createregkey (registrykey rootkey, string keypath)
{
Try
{
Return rootkey. createsubkey (keypath );
}
Catch
{
Return NULL;
}
}
/// Delete the subitem whose path is keypath
Private bool delregsubkey (registrykey rootkey, string keypath)
{
Try
{
Rootkey. deletesubkey (keypath );
Return true;
}
Catch
{
Return false;
}
}
/// Delete the subitem whose path is keypath and its subitem
Private bool delregsubkeytree (registrykey rootkey, string keypath)
{
Try
{
Rootkey. deletesubkeytree (keypath );
Return true;
}
Catch
{
Return false;
}
}
/// Delete the key value with the key name keyname in the keypath
Private bool delregkeyval (registrykey rootkey, string keypath, string keyname)
{
Try
{
Registrykey key = rootkey. opensubkey (keypath, true );
Key. deletevalue (keyname );
Return true;
}
Catch
{
Return false;
}
}
}