Guest User

Untitled

a guest
Jun 15th, 2016
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 KB | None | 0 0
  1. class RegisteryManager
  2.     {
  3.         private string keyPath = (System.Environment.Is64BitOperatingSystem) ? Global.BolRegisteryx64path : Global.BolRegisteryx86path;
  4.         private string username { get; set; }
  5.         private string password { get; set; }
  6.  
  7.         public RegisteryManager()
  8.         {
  9.             string subkey = (System.Environment.Is64BitOperatingSystem) ? "SOFTWARE\\WOW6432Node" : "SOFTWARE" ;
  10.             RegistryKey registeryKey = Registry.LocalMachine.OpenSubKey(subkey);
  11.  
  12.             if(registeryKey != null)
  13.             {
  14.                 RegistryKey bolKey = registeryKey.OpenSubKey("BOL");
  15.                
  16.                 if(bolKey == null)
  17.                 {
  18.                     registeryKey.CreateSubKey("BOL");
  19.                     bolKey = registeryKey.OpenSubKey("BOL", true);
  20.                     bolKey.SetValue(Global.BolRegisteryUsername, "default");
  21.                     bolKey.SetValue(Global.BolRegisteryPassword, "default");
  22.                 }
  23.             }
  24.         }
  25.  
  26.         public string ReadKey()
  27.         {
  28.             RegistryKey registeryKey = Registry.LocalMachine.OpenSubKey(this.keyPath);
  29.             if(registeryKey != null)
  30.             {
  31.                 String username = (String)registeryKey.GetValue(Global.BolRegisteryUsername);
  32.                 String password = (String)registeryKey.GetValue(Global.BolRegisteryPassword);
  33.  
  34.                 if (!String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(password))
  35.                 {
  36.                     return String.Concat(username, "|", password);
  37.                 }
  38.             }
  39.  
  40.             return String.Empty;
  41.         }
  42.  
  43.         public void WriteKey(string key, string value)
  44.         {
  45.             RegistryKey registeryKey = Registry.LocalMachine.OpenSubKey(this.keyPath, true);
  46.             if (registeryKey != null)
  47.             {
  48.                 registeryKey.SetValue(key, value);
  49.             }
  50.         }
  51.  
  52.         public void EraseBolKeys()
  53.         {
  54.             string subkey = (System.Environment.Is64BitOperatingSystem) ? "SOFTWARE\\WOW6432Node" : "SOFTWARE";
  55.             RegistryKey registeryKey = Registry.LocalMachine.OpenSubKey(subkey);
  56.  
  57.             if (registeryKey != null)
  58.             {
  59.                 RegistryKey bolKey = registeryKey.OpenSubKey("BOL");
  60.                 if (bolKey != null)
  61.                 {
  62.                     bolKey = registeryKey.OpenSubKey("BOL", true);
  63.                     bolKey.SetValue(Global.BolRegisteryUsername, "default");
  64.                     bolKey.SetValue(Global.BolRegisteryPassword, "default");
  65.                 }
  66.             }
  67.         }
  68.  
  69.     }
Add Comment
Please, Sign In to add comment