Пример #1
0
        public void Scan()
        {
            var currentElements = _collector.Collect();

            var added      = currentElements.Except(_elements).ToList();
            var addedCount = added.Count;

            if (addedCount > 0)
            {
                _addedElements.AddRange(added);
                AddedElementsFound?.Invoke(this, null);
            }

            var removed      = _elements.Except(currentElements).ToList();
            var removedCount = removed.Count;

            if (removedCount > 0)
            {
                _removedElements.AddRange(removed);
                RemovedElementsFound?.Invoke(this, null);
            }

            if (addedCount > 0 || removedCount > 0)
            {
                _elements = currentElements;
                ElementsUpdated?.Invoke(this, null);
            }
        }
Пример #2
0
        public ElementScaner(ISystemElementsCollector collector, string name)
        {
            _collector = collector;

            _addedElements   = new SystemElementsCollection();
            _removedElements = new SystemElementsCollection();

            Name = name;

            GetInitialCollection();
        }
Пример #3
0
        public SystemElementsCollection Collect()
        {
            var collection = new SystemElementsCollection();

            var src = new ManagementObjectSearcher("SELECT * FROM Win32_SystemDriver");

            foreach (ManagementObject obj in src.Get())
            {
                collection.Add(new Driver(obj["DisplayName"].ToString(), obj["Name"].ToString(), obj["State"].ToString()));
            }

            return(collection);
        }
Пример #4
0
        public SystemElementsCollection Collect()
        {
            var collection = new SystemElementsCollection();

            ManagementObjectSearcher cls = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_StartupCommand");

            foreach (ManagementObject mc in cls.Get())
            {
                collection.Add(new StartupProgram(mc["Name"].ToString(), mc["Location"].ToString()));
            }

            using (RegistryKey Reg = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\not active"))
            {
                if (Reg != null)
                {
                    foreach (string Programs in Reg.GetValueNames())
                    {
                        collection.Add(new StartupProgram(Programs, Reg.Name));
                    }
                }
            }

            using (RegistryKey Reg = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\not active"))
            {
                if (Reg != null)
                {
                    foreach (string Programs in Reg.GetValueNames())
                    {
                        collection.Add(new StartupProgram(Programs, Reg.Name));
                    }
                }
            }

            using (RegistryKey Reg = Registry.LocalMachine.OpenSubKey("Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run"))
            {
                foreach (string Programs in Reg.GetValueNames())
                {
                    collection.Add(new StartupProgram(Programs, Reg.Name));
                }
            }

            return(collection);
        }
Пример #5
0
        public SystemElementsCollection Collect()
        {
            var collection = new SystemElementsCollection();

            foreach (CertificateRoot root in Enum.GetValues(typeof(CertificateRoot)))
            {
                var store = new X509Store(root.ToString(), StoreLocation.CurrentUser);
                try
                {
                    store.Open(OpenFlags.ReadOnly);
                    foreach (X509Certificate2 mCert in store.Certificates)
                    {
                        collection.Add(new Certificate(root, mCert)
                        {
                            Hive = Hive.Users
                        });
                    }
                }
                finally
                {
                    store.Close();
                }

                store = new X509Store(root.ToString(), StoreLocation.LocalMachine);
                try
                {
                    store.Open(OpenFlags.ReadOnly);
                    foreach (X509Certificate2 mCert in store.Certificates)
                    {
                        collection.Add(new Certificate(root, mCert)
                        {
                            Hive = Hive.Machines
                        });
                    }
                }
                finally
                {
                    store.Close();
                }
            }

            return(collection);
        }
Пример #6
0
        public SystemElementsCollection Collect()
        {
            var collection = new SystemElementsCollection();

            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"))
            {
                foreach (string driver in key.GetValueNames())
                {
                    collection.Add(new ODBC(driver));
                }
            }

            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\ODBC\ODBCINST.INI\ODBC Drivers"))
            {
                foreach (string driver in key.GetValueNames())
                {
                    collection.Add(new ODBC(driver + " (x86)"));
                }
            }

            return(collection);
        }
        public SystemElementsCollection Collect()
        {
            var collection = new SystemElementsCollection();

            foreach (DictionaryEntry de in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User))
            {
                collection.Add(new EnvironmentVariable(de.Key.ToString(), de.Value.ToString())
                {
                    Hive = Hive.Users
                });
            }

            foreach (DictionaryEntry de in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine))
            {
                collection.Add(new EnvironmentVariable(de.Key.ToString(), de.Value.ToString())
                {
                    Hive = Hive.Machines
                });
            }

            return(collection);
        }
Пример #8
0
        public void CompareSnapshots(
            Snapshot oldSnapshot,
            Snapshot newSnapshot,
            out List <SystemElementsCollection> addedElementsCollections,
            out List <SystemElementsCollection> removedElementsCollections)
        {
            addedElementsCollections   = new List <SystemElementsCollection>();
            removedElementsCollections = new List <SystemElementsCollection>();
            for (var i = 0; i < oldSnapshot.Collections.Count; i++)
            {
                //var name = oldSnapshot.Collections[i].Name;

                var addedElementsList = oldSnapshot.Collections[i].Except(newSnapshot.Collections[i]).ToList();
                var addedElements     = new SystemElementsCollection(/*name*/);
                addedElements.AddRange(addedElementsList);
                addedElementsCollections.Add(addedElements);

                var removedElementsList = newSnapshot.Collections[i].Except(oldSnapshot.Collections[i]).ToList();
                var removedElements     = new SystemElementsCollection(/*name*/);
                removedElements.AddRange(removedElementsList);
                removedElementsCollections.Add(removedElements);
            }
        }
Пример #9
0
 private void GetInitialCollection()
 {
     _elements = _collector.Collect();
 }