Search

Write a Registry key

This C# code snippet writes a key to the Windows Registry.
using Microsoft.Win32;

RegistryKey masterKey = Registry.LocalMachine.CreateSubKey
   ("SOFTWARE\\Test\\customkey");
if (masterKey == null)
{
   Console.WriteLine ("Null Masterkey!");
}
else
{
   try
   {
      masterKey.SetValue ("MyKey", "MyValue");
   }
   catch (Exception ex)
   {
      Console.WriteLine (ex.Message);
   }
   finally
   { 
      masterKey.Close();
   }
}