c read write registration representation sharing
- 2020-06-03 08:05:26
- OfStack
// Write the registry
RegistryKey regWrite;
// to HKEY_CURRENT_USER In the primary key Software Son write under the key 1 Called" Test "A child of the key
// if Test The subkey already exists and the system will override it automatically
regWrite = Registry.CurrentUser.CreateSubKey("Software\\Test");
// to Test I'm going to put two items in the child key, 1 Article named "Name", On the other 1 Article named "Sex"
// Values are respectively "luolie"," male "
regWrite.SetValue("Name","luolie");
regWrite.SetValue("Sex"," male ");
// Close the object
regWrite.Close();
// Read the registry
RegistryKey regRead;
// read HKEY_CURRENT_USER In the primary key Software The subkey is called" Test "A child of the key
regRead= Registry.CurrentUser.OpenSubKey("Software\\Test",true);
if(regRead==null) // If the child key does not exist
{
MessageBox.Show("No Data!") ;
}
else
{
object obj= regRead.GetValue("Name"); // Read" Name "The value of the item
textBox1.Text = obj.ToString(); // Displayed in the TextBox In the
}
// Close the object
oReg.Close();