Saturday, December 3, 2011

   1:  using Microsoft.Win32;
   2:  public static bool WriteDefaulConStr(string str)
   3:              {
   4:              try {
   5:                  RegistryKey rk = Registry.CurrentUser;
   6:                  RegistryKey sk1 = rk.CreateSubKey(@"Software\abc\efg\hij\");
   7:                  sk1.SetValue("abc", str);
   8:                  return true;
   9:                  }
  10:              catch (Exception e) {
  11:                  ErrorInRegWriting = e.Message + "\nERROR CODE RG000";
  12:                  return false;
  13:                  }
  14:              }
  15:   
  16:  public static string ReadDefaulConStr() 
  17:              {
  18:              RegistryKey rk = Registry.CurrentUser;
  19:              RegistryKey sk1 = rk.OpenSubKey(@"Software\abc\efg\hij\");
  20:   
  21:              if (sk1 == null) 
  22:                  {
  23:                  return "NULL_KEY";
  24:                  }
  25:              else 
  26:                 {
  27:                  try {
  28:                      return (string)sk1.GetValue("abc");
  29:                      }
  30:                  catch (Exception e) 
  31:                      {                   
  32:                      return "NULL_KEY:" + "\n" + e.Message;
  33:                      }
  34:                }
  35:        }