コード例 #1
0
        private static ObjectQuery GetChildQuery(string className, ManagementBaseObject config)
        {
            var parent = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.ParentProperty);
            var name   = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty);

            return(GetChildQuery(className, CatalogueName.GetFullName(parent, name)));
        }
コード例 #2
0
        private static EventType CreateEventType(Catalogue catalogue, ManagementBaseObject config)
        {
            // Get the properties.

            var name      = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty);
            var isEnabled = (bool)WmiUtil.GetPropertyValue(config, Constants.Wmi.EventType.IsEnabledProperty);

            return(catalogue.CreateEventType(catalogue, name, isEnabled));
        }
コード例 #3
0
        private static Source CreateSource(ISourceParent parent, ManagementBaseObject config)
        {
            // Get the properties.

            var name          = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty);
            var enabledEvents = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.Source.EnabledEventsProperty);

            string[] enabledEventsArray = SplitString(enabledEvents, Constants.Module.ListSeparator);
            return(parent.Catalogue.CreateSource(parent, name, enabledEventsArray));
        }
コード例 #4
0
        private void DeleteEventType(IElement eventType)
        {
            // Get the configuration for this source.

            ManagementObject config = WmiUtil.GetObject(_scope, GetPath(eventType));

            if (config != null)
            {
                DeleteEventType(config);
            }
        }
コード例 #5
0
        private void DeleteSource(Source source)
        {
            // Get the configuration for this source.

            ManagementObject config = WmiUtil.GetObject(_scope, GetPath(source));

            if (config != null)
            {
                DeleteSource(config);
            }
        }
コード例 #6
0
        private void DeleteNamespace(Namespace ns)
        {
            // Get the configuration for this source.

            ManagementObject config = WmiUtil.GetObject(_scope, GetPath(ns));

            if (config != null)
            {
                DeleteNamespace(config);
            }
        }
コード例 #7
0
ファイル: WmiConnection.cs プロジェクト: formist/LinkMe
        private static string GetSourceFullyQualifiedReference(EventArrivedEventArgs e)
        {
            var config = (ManagementBaseObject)WmiUtil.GetPropertyValue(e.NewEvent, "TargetInstance");

            Debug.Assert(config != null, "config != null");

            var name   = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty);
            var parent = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.ParentProperty);

            return(CatalogueName.GetQualifiedReferenceUnchecked(parent, name));
        }
コード例 #8
0
        public void EventStatusChanged(CatalogueElements elementType, string fullName)
        {
            // Store the changes in static properties on the LinkMe_InstrumentationEventStatusChange class.

            var config = new ManagementClass(_scope,
                                             new ManagementPath(Constants.Wmi.EventStatusChange.Class), null);

            WmiUtil.SetPropertyValue(config, Constants.Wmi.EventStatusChange.FullNameProperty, fullName);
            WmiUtil.SetPropertyValue(config, Constants.Wmi.EventStatusChange.ElementTypeProperty, (int)elementType);

            config.Put();
        }
コード例 #9
0
        public static IList <ProcessInfoViewModel> LoadProcesses()
        {
            var processInfoList = WmiUtil.QueryProcesses().AsParallel()
                                  .Select(mgmtObj => BuildProcessInfo(mgmtObj))
                                  .OrderBy(p => p.ProcessId);

            //var processInfoList = Process.GetProcesses().AsParallel()
            //                                            .Select(p => BuildProcessInfo(p))
            //                                            .OrderBy(p => p.ProcessId);

            return(new List <ProcessInfoViewModel>(processInfoList));
        }
コード例 #10
0
ファイル: WmiConnection.cs プロジェクト: formist/LinkMe
        private void HandleEventModification(object sender, EventArrivedEventArgs e)
        {
            string name;
            bool   isEnabled;

            try
            {
                // Read the details of the change.

                var config = (ManagementBaseObject)WmiUtil.GetPropertyValue(
                    e.NewEvent, "TargetInstance");
                Debug.Assert(config != null, "config != null");

                name      = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty);
                isEnabled = (bool)WmiUtil.GetPropertyValue(config, Constants.Wmi.EventType.IsEnabledProperty);
            }
            catch (System.Exception ex)
            {
                HandleNotificationException(ex);
                return;
            }

            // Work through the callbacks.

            _lock.AcquireReaderLock(Timeout.Infinite);

            try
            {
                foreach (IRepositoryCallback callback in _callbacks)
                {
                    try
                    {
                        callback.EventChanged(name, isEnabled);
                    }
                    catch
                    {
                    }
                }
            }
            finally
            {
                _lock.ReleaseReaderLock();
            }
        }
コード例 #11
0
ファイル: WmiConnection.cs プロジェクト: formist/LinkMe
        private void HandleEventStatusChange(object sender, EventArrivedEventArgs e)
        {
            string            fullName;
            CatalogueElements elementType;

            try
            {
                // Read the details of the change.

                var config = (ManagementBaseObject)WmiUtil.GetPropertyValue(
                    e.NewEvent, "TargetClass");
                Debug.Assert(config != null, "config != null");

                fullName    = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.EventStatusChange.FullNameProperty);
                elementType = (CatalogueElements)WmiUtil.GetPropertyValue(config, Constants.Wmi.EventStatusChange.ElementTypeProperty);
            }
            catch (System.Exception ex)
            {
                HandleNotificationException(ex);
                return;
            }

            // Work through the callbacks.

            _lock.AcquireReaderLock(Timeout.Infinite);

            try
            {
                foreach (IRepositoryCallback callback in _callbacks)
                {
                    try
                    {
                        callback.EventStatusChanged(elementType, fullName);
                    }
                    catch
                    {
                    }
                }
            }
            finally
            {
                _lock.ReleaseReaderLock();
            }
        }
コード例 #12
0
        private void UpdateEventType(EventType eventType)
        {
            // Try to get an existing source.

            ManagementObject config = WmiUtil.GetObject(_scope, GetPath(eventType));

            if (config == null)
            {
                // Not found, so create a new instance.

                config = CreateInstance(Constants.Wmi.EventType.Class);
                WmiUtil.SetPropertyValue(config, Constants.Wmi.NameProperty, eventType.Name);
            }

            // Update the rest of the properties and save.

            WmiUtil.SetPropertyValue(config, Constants.Wmi.EventType.IsEnabledProperty, eventType.IsEnabled);
            config.Put();
        }
コード例 #13
0
        private void UpdateSource(Source source)
        {
            // Try to get an existing source.

            ManagementObject config = WmiUtil.GetObject(_scope, GetPath(source));

            if (config == null)
            {
                // Not found, so create a new instance.

                config = CreateInstance(Constants.Wmi.Source.Class);
                WmiUtil.SetPropertyValue(config, Constants.Wmi.ParentProperty, source.Parent == null ? string.Empty : source.Parent.FullName);
                WmiUtil.SetPropertyValue(config, Constants.Wmi.NameProperty, source.Name);
            }

            // Update the rest of the properties and save.

            string enabledEvents = JoinString(source.EnabledEvents, Constants.Module.ListSeparator);

            WmiUtil.SetPropertyValue(config, Constants.Wmi.Source.EnabledEventsProperty, enabledEvents);
            config.Put();
        }
コード例 #14
0
ファイル: WmiConnection.cs プロジェクト: formist/LinkMe
        private void InitialiseCallback()
        {
            _lock      = new ReaderWriterLock();
            _callbacks = new ArrayList();

            var scope = new ManagementScope(InitialisationString);

            scope.Connect();

            // Event enable/disable notifications - these are stored as static properties on the
            // LinkMe_InstrumentationEventStatusChange class.

            var query = new WqlEventQuery("__ClassModificationEvent",
                                          "TargetClass isa \"" + Constants.Wmi.EventStatusChange.Class + "\"");

            WmiUtil.StartEventWatcher(scope, query, HandleEventStatusChange);

            // Watch for modifications of the LinkMe_InstrumentationEvent class to pick up changes to default
            // event status.

            query = new WqlEventQuery("__InstanceModificationEvent", "TargetInstance isa \""
                                      + Constants.Wmi.EventType.Class + "\"");
            WmiUtil.StartEventWatcher(scope, query, HandleEventModification);

            // Watch for creation of new LinkMe_InstrumentationSource objects.

            query = new WqlEventQuery("__InstanceCreationEvent", "TargetInstance isa \""
                                      + Constants.Wmi.Source.Class + "\"");
            WmiUtil.StartEventWatcher(scope, query, HandleSourceCreation);

            // Watch for deletion of LinkMe_InstrumentationSource objects.

            query = new WqlEventQuery("__InstanceDeletionEvent", "TargetInstance isa \""
                                      + Constants.Wmi.Source.Class + "\"");
            WmiUtil.StartEventWatcher(scope, query, HandleSourceDeletion);

            // TODO: Need to work out how to stop - implement IDisposable? In practice only Instrumentation
            // runtime registeres a callback and it never stops until the AppDomain is shut down, anyway.
        }
コード例 #15
0
        public Namespace GetNamespace(INamespaceParent parent, string relativeName, bool ignoreCase)
        {
            // WMI is very slow, so do everything possible to minimise WMI access. We need to load all the
            // namespaces in the hierarchy (from the parent to the one being sought), because any of them
            // may have enabled events. Get them all in one query.

            // Build a query that gets all the namespaces we need (if they exist).

            string[] nsParts        = relativeName.Split('.');
            string   parentFullName = parent.FullName;
            string   queryString    = BuildQueryStringForNamespaces(nsParts, parentFullName);

            // WQL is case-insensitive, so if ignoreCase is false use the Hashtable created below to filter.

            Hashtable namespaces = ignoreCase ? new Hashtable(StringComparer.InvariantCultureIgnoreCase) : new Hashtable();

            var searcher = new ManagementObjectSearcher(_scope, new ObjectQuery(queryString));

            // Read the namespaces returned and store them temporarily in a Hasthable. We cannot create
            // Namespace objects as we go, because they may be returned out of order (ie. children before parents).

            using (ManagementObjectCollection configs = searcher.Get())
            {
                foreach (ManagementObject config in configs)
                {
                    var details = new NamespaceDetails();

                    var nsName        = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty);
                    var nsParentName  = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.ParentProperty);
                    var enabledEvents = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.Namespace.EnabledEventsProperty);
                    var mixedEvents   = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.Namespace.MixedEventsProperty);

                    details._enabledEvents = SplitString(enabledEvents, Constants.Module.ListSeparator);
                    details._mixedEvents   = SplitString(mixedEvents, Constants.Module.ListSeparator);

                    namespaces.Add(CatalogueName.GetFullNameUnchecked(nsParentName, nsName), details);
                }
            }

            // Now that we have all the details create the hierarchy of Namespace objects.

            Catalogue catalogue = parent.Catalogue;
            Namespace ns        = null;

            foreach (string nsName in nsParts)
            {
                string nsFullName = CatalogueName.GetFullNameUnchecked(parentFullName, nsName);
                var    details    = (NamespaceDetails)namespaces[nsFullName];
                if (details == null)
                {
                    return(null);                    // One of the namespaces in the path was not found in WMI.
                }
                ns = catalogue.CreateNamespace(parent, nsName, details._enabledEvents, details._mixedEvents);
                parent.AddIfNotLoaded(ns);

                parentFullName = nsFullName;
                parent         = ns;
            }

            return(ns);
        }