public void TestWriteValue()
        {
            //Setup
            RegistryEdit reg = new RegistryEdit();
            KeyObject keyObject = new KeyObject("firstname", "lastname", "TestCompany", "TestProductName", "1.0.0");
            string regPath = KeyUtil.BuildRegPath(keyObject);
            Assert.IsNotNull(reg.WriteKey(regPath)); 
            //Execute    
            try
            {
                reg.WriteValue(null, null, null);
            }
            catch (Exception ex) { Assert.IsTrue(true, ex.Message); }

            try
            {
                reg.WriteValue(regPath, "testkey", null);
            }
            catch (Exception ex) { Assert.IsTrue(true, ex.Message); }

            Assert.IsTrue(reg.WriteValue(regPath, "testkey", "testvalue")); 
            //Verify
            //Undo
            Assert.IsTrue(reg.DeleteKey(regPath, "TestCompany"));
        }
 public void TestDeleteKey()
 {
     //Setup
     RegistryEdit reg = new RegistryEdit();
     KeyObject keyObject = new KeyObject("firstname", "lastname", "TestCompany", "TestProductName", "1.0.0");
     string regPath = KeyUtil.BuildRegPath(keyObject);
     Assert.IsNotNull(reg.WriteKey(regPath)); 
     //Execute  
     Assert.IsTrue(reg.DeleteKey(regPath, "TestCompany"));
     //Verify
     Assert.IsNull(reg.Read(regPath)); 
     //Undo
 }
Example #3
0
 public static DateTime GetExpireDate(KeyObject key)
 {
     RegistryEdit reg = new RegistryEdit();
     RegistryKey regKey = reg.Read(BuildRegPath(key));
     object regValue = regKey.GetValue("ExpireDate");
     try
     {
         return DateTime.Parse(regValue.ToString());
     }
     catch 
     {
         return DateTime.MinValue;//Invalid date
     }
 }
 public void TestRead()
 {
     //Setup
     RegistryEdit reg = new RegistryEdit();
     KeyObject keyObject = new KeyObject("firstname", "lastname", "TestCompany", "TestProductName", "1.0.0");
     string regPath = KeyUtil.BuildRegPath(keyObject);
     reg.DeleteKey(regPath, "TestCompany");
     //Execute  
     //Verify
     try 
     {
         reg.Read(null);
     }
     catch (Exception ex) { Assert.IsTrue(true, ex.Message); }
     Assert.IsNull(reg.Read(regPath)); //Non-existant reg key
     //Undo
 }
Example #5
0
 public static bool InstallKey(KeyObject key)
 {
     RegistryEdit reg = new RegistryEdit();
     string keyPath = BuildRegPath(key);
     RegistryKey regKey = reg.WriteKey(keyPath);
     if (regKey != null)
     {
         bool isKeyNameWritten = reg.WriteValue(keyPath, "KeyName", key.Name);
         bool isKeyCodeWritten = reg.WriteValue(keyPath, "KeyCode", key.Key);
         bool isExpireDateWritten = reg.WriteValue(keyPath, "ExpireDate", key.ExpireDate);
         return isKeyNameWritten & isKeyCodeWritten & isExpireDateWritten;
     }
     else
     {
         return false;
     }
 }
Example #6
0
        public static KeyObject GetInstalledKey(string companyName, string productName, string productVersion)
        {
            KeyObject key = new KeyObject("", "", companyName, productName, productVersion);
            string regPath = BuildRegPath(key);
            RegistryEdit reg = new RegistryEdit();
            RegistryKey regKey = reg.Read(regPath);
            if (regKey == null) return null;

            object keyName = regKey.GetValue("KeyName");
            object keyCode = regKey.GetValue("KeyCode");
            if (keyName != null)
                key.Name = keyName.ToString();

            if (keyCode != null)
                key.Key = keyCode.ToString();
            return key;
        }
Example #7
0
        public static bool IsKeyInstalled(KeyObject key)
        {            
            RegistryKey regKey = null;

            if (key != null)
            {
                string regPath = BuildRegPath(key);
                RegistryEdit reg = new RegistryEdit();
                regKey = reg.Read(regPath);
                if ((regKey != null) &&
                    ((regKey.GetValue("KeyName").ToString() == key.Name) & (regKey.GetValue("KeyCode").ToString() == key.Key)))
                {
                    return true;
                }
            }

            return false; //If we make it this far, the key was not installed.
        }
Example #8
0
 public static bool UninstallKey(KeyObject key)
 {
     RegistryEdit reg = new RegistryEdit();
     string keyPath = BuildRegPath(key);
     return reg.DeleteKey(keyPath, key.CompanyName);
 }