Write a Text and DWord Value to the Registry : Registry « Windows « C# / C Sharp






Write a Text and DWord Value to the Registry

using System;
using Microsoft.Win32;
   

  class Class1
  {
    static void Main(string[] args)
    {
      RegistryKey RegKeyWrite = Registry.CurrentUser;
      RegKeyWrite = RegKeyWrite.CreateSubKey("Software\\CSHARP\\WriteRegistryValue");
      RegKeyWrite.SetValue("StringValue","TRUE");
      RegKeyWrite.SetValue("Number",100);
      RegKeyWrite.Close();
   
      RegistryKey RegKeyRead = Registry.CurrentUser;
      RegKeyRead = RegKeyRead.OpenSubKey  ("Software\\CSHARP\\WriteRegistryValue");
      Object regSuccessful = RegKeyRead.GetValue("StringValue");
      Object regAttemptNumber = RegKeyRead.GetValue("Number");
      RegKeyRead.Close();
   
      if ((string)regSuccessful == "TRUE")
        Console.WriteLine("Succeeded on attempt # {0}",regAttemptNumber);
      else
        Console.WriteLine("Failed!");
    }
  }

           
       








Related examples in the same category

1.Save value to registery
2.Read value from registry
3.Retrieve the CPU Type and Speed from the Registry
4.Enumerating Registry Keys
5.Get registry value from LocalMachine key