Exemplo n.º 1
0
        public void SetValueData_WithoutValueNameInPath()
        {
            var TestValueData = "Test Value Data";

            AdvRegistry.SetValueData(ExistentKeyPath, TestValueData);
            Assert.AreEqual(TestValueData, AdvRegistry.GetValueData(ExistentKeyPath));
        }
Exemplo n.º 2
0
        public void SetValueData_ExistentKeyNonexitentVal()
        {
            var TestValueData = "Test Value Data";

            AdvRegistry.SetValueData(ExistentKey_NonexistentVal_Path, TestValueData);
            Assert.AreEqual(TestValueData, AdvRegistry.GetValueData(ExistentKey_NonexistentVal_Path));
        }
Exemplo n.º 3
0
        private void treeRegistry_AfterExpand(object sender, TreeViewEventArgs e)
        {
            TreeNode CurrentTreeNode = e.Node;

            try
            {
                // Remove dummy node.
                CurrentTreeNode.Nodes["\\dummy"].Remove();

                // Open key associated with current node.
                RegistryKey CurrentKey = AdvRegistry.OpenSubKey(CurrentTreeNode.FullPath);

                // Populate keys.
                foreach (String CurrentSubKeyName in CurrentKey.GetSubKeyNames())
                {
                    AddKey(CurrentTreeNode, CurrentSubKeyName);
                }

                // Populate values.
                foreach (String CurrentValueName in CurrentKey.GetValueNames())
                {
                    AddValue(CurrentTreeNode, CurrentValueName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 4
0
        public void DeleteKey_ForExistentKeyWithSubkeys()
        {
            AdvRegistry.CreateKey(ExistentKeyPath + "\\Subkey1");
            AdvRegistry.CreateKey(ExistentKeyPath + "\\Subkey2");

            AdvRegistry.DeleteKey(ExistentKeyPath);
            Assert.IsFalse(AdvRegistry.IsKeyExists(ExistentKeyPath));
        }
Exemplo n.º 5
0
        private static string[] ExpandFSPaths(Ruleset.PathsRow path)
        {
            var Result = new List <string>();

            if (!AdvRegistry.IsRegistryPath(path.Path))
            {
                Result.Add(AdvEnvironment.ExpandEnvironmentVariables(path.Path));
            }

            return(Result.ToArray());
        }
Exemplo n.º 6
0
        public void TestOpenSubKey()
        {
            // Is OpenSubKey able to open existent path?
            var key = AdvRegistry.OpenSubKey(ExistentKeyPath);

            Assert.AreEqual(key.Name, "HKEY_CURRENT_USER\\existent");

            // Is OpenSubKey able to open path which contains only root element?
            key = AdvRegistry.OpenSubKey("HKLM");
            Assert.AreEqual(Registry.LocalMachine, key);

            // When opening nonexistent path OpenSubKye must return null
            key = AdvRegistry.OpenSubKey(NonexistentKeyPath);
            Assert.IsNull(key);
        }
Exemplo n.º 7
0
        private static int Benchmark(Ruleset ruleset, int benchmarkTime)
        {
            int accessCounter = 0;

            var time = DateTime.Now.AddMinutes(benchmarkTime);

            while (DateTime.Now < time)
            {
                foreach (Ruleset.PathsRow path in ruleset.Paths)
                {
                    // Try to open every file in list.
                    foreach (var fsPath in ExpandFSPaths(path))
                    {
                        FileStream file = null;
                        try
                        {
                            if (File.Exists(fsPath))
                            {
                                file = File.Open(fsPath, FileMode.Open, FileAccess.Read);
                            }
                        }
                        catch
                        {
                        }
                        finally
                        {
                            if (file != null)
                            {
                                file.Close();
                            }
                        }
                    }

                    if (AdvRegistry.IsRegistryPath(path.Path) && AdvRegistry.IsKeyExists(path.Path))
                    {
                        AdvRegistry.GetValueData(path.Path);
                    }
                }
                accessCounter++;
                Console.Write(".");
            }
            Console.WriteLine();

            return(accessCounter);
        }
Exemplo n.º 8
0
 public void IsRegistryPathOnIcorrectData()
 {
     string[] TestRegistryPaths = new[]
     {
         @"C:\Documents and Settings",
         @"C:\Documents and Settings\All Users\Favorites",
         @"D:\Documents\Pictures",
         @"HKY_CURRENT_USER\Printers\\DeviceOld",
         @"HKEY_LOCAL_MACHIN\SOFTWARE\FGUpdate\Config\\Time1"
     };
     foreach (var RegistryPath in TestRegistryPaths)
     {
         if (AdvRegistry.IsRegistryPath(RegistryPath))
         {
             Assert.Fail("AdvRegistry.IsRegistryPath returned true on:\r\n" + RegistryPath);
         }
     }
 }
Exemplo n.º 9
0
        public void CreateKey()
        {
            if (Registry.CurrentUser.OpenSubKey("TestKey") != null)
            {
                Assert.Fail(@"HKCU\TestKey already exists.");
            }

            AdvRegistry.CreateKey(@"HKCU\TestKey");

            if (Registry.CurrentUser.OpenSubKey("TestKey") == null)
            {
                Assert.Fail(@"HKCU\TestKey failed to create.");
            }
            else
            {
                Registry.CurrentUser.DeleteSubKey("TestKey");
            }
        }
Exemplo n.º 10
0
 public void IsRegistryPath()
 {
     string[] TestRegistryPaths = new[]
     {
         @"HKEY_LOCAL_MACHINE\SOFTWARE\FGUpdate\Config",
         @"HKEY_LOCAL_MACHINE\SOFTWARE\Windows 3.1 Migration Status\REG.DAT",
         @"HKEY_USERS\S-1-5-21-515967899-606747145-682003330-500\Identities\{30EA52FF-4D40-469E-B12F-CE5262A1495F}\Software\Microsoft\Outlook Express\5.0\Rules\Filter\FFA\Actions\000",
         @"HKEY_CURRENT_USER\Printers\\DeviceOld",
         @"HKEY_LOCAL_MACHINE\SOFTWARE"
     };
     foreach (var RegistryPath in TestRegistryPaths)
     {
         if (!AdvRegistry.IsRegistryPath(RegistryPath))
         {
             Assert.Fail("AdvRegistry.IsRegistryPath returned false on:\r\n" + RegistryPath);
         }
     }
 }
Exemplo n.º 11
0
        public void Initialize()
        {
            var Key = Registry.CurrentUser.CreateSubKey("existent");

            if (Key == null)
            {
                throw new ApplicationException("Can't create existent key in HKCU.");
            }

            Key.SetValue("existent", "TEST");

            if (Registry.CurrentUser.OpenSubKey("nonexistent") != null)
            {
                throw new ApplicationException("nonexistent key exists in HKCU.");
            }

            if (AdvRegistry.GetValueData(ExistentKey_NonexistentVal_Path) != null)
            {
                throw new ApplicationException("nonexistent val exists in HKCU\\existent.");
            }
        }
Exemplo n.º 12
0
 public void SetValueData_NullKey()
 {
     AdvRegistry.SetValueData(null, "Test value data.");
 }
Exemplo n.º 13
0
 public void DeleteKey_ForNonexistentKey()
 {
     AdvRegistry.DeleteKey(NonexistentKeyPath);
 }
Exemplo n.º 14
0
 public void SetValueData_EmptyKey()
 {
     AdvRegistry.SetValueData("", "Test value data.");
 }
Exemplo n.º 15
0
 public void GetValueData()
 {
     Assert.AreEqual("TEST", AdvRegistry.GetValueData(ExistentValPath));
 }
Exemplo n.º 16
0
 public void SetValueData_NullData()
 {
     AdvRegistry.SetValueData(ExistentValPath, null);
 }
Exemplo n.º 17
0
 public void SetValueData_EmptyData()
 {
     AdvRegistry.SetValueData(ExistentValPath, "");
     Assert.AreEqual(string.Empty, AdvRegistry.GetValueData(ExistentValPath));
 }
Exemplo n.º 18
0
 public void SetValueData_NonexistentKey()
 {
     AdvRegistry.SetValueData(NonexistentKeyPath, string.Empty);
 }
Exemplo n.º 19
0
 public void DeleteKey_ForExistentKey()
 {
     AdvRegistry.DeleteKey(ExistentKeyPath);
     Assert.IsFalse(AdvRegistry.IsKeyExists(ExistentKeyPath));
 }
Exemplo n.º 20
0
 public void IsKeyExists()
 {
     Assert.AreEqual(AdvRegistry.IsKeyExists(ExistentKeyPath), true);
     Assert.AreEqual(AdvRegistry.IsKeyExists(NonexistentKeyPath), false);
 }