The Registry class and RegistryKey class are provided in VC # To perform Registry operations.
WhereRegistryClassIt encapsulates the seven basic keys of the registry:
Registry. ClassesRoot corresponds to the HKEY_CLASSES_ROOT primary key
Registry. CurrentUser corresponds to the HKEY_CURRENT_USER primary key
Registry. LocalMachine corresponds to the HKEY_LOCAL_MACHINE primary key
Registry. User corresponds to the HKEY_USER primary key
Registry. CurrentConfig corresponds to the primary key of HEKY_CURRENT_CONFIG
Registry. DynDa corresponds to the HKEY_DYN_DATA primary key
Registry. PerformanceData corresponds to the HKEY_PERFORMANCE_DATA primary key.
RegistryKeyClassIt encapsulates basic operations on the registry, including reading, writing, and deleting.
WhereRead Main FunctionsInclude:
OpenSubKey (string name) is used to open a specified subkey.
The GetSubKeyNames () method is used to obtain the names of all subkeys under the primary key. The returned value is a string array.
The GetValueNames () method is used to obtain all the key names in the current subkey, and its return value is also a string array.
The GetValue (string name) method specifies the key value of a key.
Written functions:
The CreateSubKey (string name) method adds a subkey.
SetValue (string name, string value) is used to set the key value of a key.
Deleted functions:
DeleteSubKey () method: deletes a specified subkey.
DeleteSubKeyTree () method: This method completely deletes the specified sub-Key Directory, that is, deleting the sub-key and all sub-keys below the sub-key.
In the following example, note the following:
Create a function: CreateSubKey ()
Create a subkey function: SetValue ();
Class Program
{
Static string Generateguid () // creates a GUID Value Function
{
Return System. Guid. NewGuid (). ToString ();
}
Static void Main (string [] args)
{
RegistryKey pregkey;
String preName;
// Pregkey = Registry. CurrentUser. OpenSubKey ("Control Panel \ Desktop \ WindowMetrics", true );
Pregkey = Registry. LocalMachine. OpenSubKey ("SOFTWARE \ Microsoft \ Internet Explorer \ Extensions", true); // retrieve subitem in read-only mode
If (pregkey = null)
{
Console. WriteLine ("this key does not exist ");
}
Else
{
PreName = Generateguid ();
Console. WriteLine (preName );
Console. WriteLine ("find this key value ");
PreName = "{" + preName + "}";
// Pregkey. SetValue ("MinAnimate", "1 ");
Pregkey. CreateSubKey (preName); // create a subitem
Pregkey = Registry. LocalMachine. OpenSubKey ("SOFTWARE \ Microsoft \ Internet Explorer \ Extensions \" + preName, true );
// Pregkey. SetValue ("bbbbb", "0"); // create a subkey. If this subkey exists, set the value.
Pregkey. SetValue ("ButtonText", "add"); // The text displayed when you place the cursor over the bar
Pregkey. SetValue ("CLSID", "{1fba04ee-3024-11d2-8f1f-440f87abd16}"); // fixed CLSID
Pregkey. SetValue ("Default Visible", "yes"); // Visible by Default
Pregkey. SetValue ("Exec", "D:/IEbar/IEpinout.exe"); // The associated exe file
Pregkey. SetValue ("HotIcon", "D:/IEbar/Icon2.ico"); // The image displayed when you place the cursor over the bar
Pregkey. SetValue ("Icon", "D:/IEbar/Icon1.ico"); // The image displayed when the mouse is not placed on the bar
// Pregkey. SetValue ("MenuStatusBar", "Yang ");
// Pregkey. SetValue ("MenuText", "I am Yang! ");
}
Pregkey. Close ();
}