Answers for "does Registry.CurrentUser.OpenSubKey create the key if it does not exist?"

C#
0

does Registry.CurrentUser.OpenSubKey create the key if it does not exist?

// No it does not - create it manually on null check
public void ConfigureWindowsRegistry()
{
    RegistryKey localMachine = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64); //here you specify where exactly you want your entry

   var reg = localMachine.OpenSubKey("Software\\Microsoft\\Office\\Outlook\\FormRegions\\tesssst",true);
   if (reg == null)
   {
       reg = localMachine.CreateSubKey("Software\\Microsoft\\Office\\Outlook\\FormRegions\\tesssst");
   }

   if (reg.GetValue("someKey") == null)
   {
       reg.SetValue("someKey", "someValue");
   }
}
Posted by: Guest on August-21-2020

Code answers related to "does Registry.CurrentUser.OpenSubKey create the key if it does not exist?"

C# Answers by Framework

Browse Popular Code Answers by Language