当前位置: 首页>>代码示例>>C#>>正文


C# Management.ManagementEventWatcher类代码示例

本文整理汇总了C#中System.Management.ManagementEventWatcher的典型用法代码示例。如果您正苦于以下问题:C# ManagementEventWatcher类的具体用法?C# ManagementEventWatcher怎么用?C# ManagementEventWatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ManagementEventWatcher类属于System.Management命名空间,在下文中一共展示了ManagementEventWatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: iosSyslogger

        public iosSyslogger()
        {
            InitializeComponent();

            var watcher = new ManagementEventWatcher();

            //Allow data copy here
            mnu = new ContextMenuStrip();
            ToolStripMenuItem mnuCopy = new ToolStripMenuItem("Copy");
            mnu.Items.AddRange(new ToolStripItem[] { mnuCopy });

            mnuCopy.Click += new EventHandler(copyMnu_Click);

            this.loglevelCheckBox.SelectedIndexChanged += new System.EventHandler(this.checkbox_SelectedIndexChanged);
            this.processlistname.SelectedIndexChanged += new System.EventHandler(this.checkbox_SelectedIndexChanged);

            //Button Click Handler
            this.highlightBtn.Click += new System.EventHandler(this.highlightBtn_Click);
            this.clearSearchBtn.Click += new System.EventHandler(this.clearSearchBtn_Click);
            this.fixScroll.Click += new System.EventHandler(this.fixScroll_Click);
            this.searchBtn.Click += new System.EventHandler(this.searchBtn_Click);
            this.savedatagrid.Click += new System.EventHandler(this.saveBtn_Click);
            this.load.Click += new System.EventHandler(this.loadBtn_click);
            this.clearData.Click += new System.EventHandler(this.clearDataBtn_Click);
        }
开发者ID:hyunmin90,项目名称:iosLoggerForWindows,代码行数:25,代码来源:Form1.cs

示例2: AddRemoveUSBHandler

        static void AddRemoveUSBHandler()
        {
            WqlEventQuery q;

            try
            {
                q = new WqlEventQuery();
                q.EventClassName = "__InstanceDeletionEvent";
                q.WithinInterval = pollInterval;
                //q.Condition = "TargetInstance ISA 'Win32_USBControllerdevice'";
                q.Condition = "TargetInstance ISA 'Win32_PnPEntity'";
                //w = new ManagementEventWatcher(scope, q);
                w = new ManagementEventWatcher(q);
                w.EventArrived += USBRemoved;

                w.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                if (w != null)
                {
                    w.Stop();
                }
            }
        }
开发者ID:kroneyisland,项目名称:WMIUSBMonitor,代码行数:26,代码来源:Program.cs

示例3: Run

        public static void Run()
        {
            // Create event query to be notified within 1 second of
            // a new process being created
            WqlEventQuery query =
                new WqlEventQuery("__InstanceCreationEvent",
                new TimeSpan(0, 0, 1),
                "TargetInstance isa \"Win32_Process\"");

            // Initialize an event watcher and subscribe to events
            // that match this query
            ManagementEventWatcher watcher =
                new ManagementEventWatcher(query);
            // times out watcher.WaitForNextEvent in 5 seconds
            watcher.Options.Timeout = new TimeSpan(0, 0, 5);

            // Block until the next event occurs
            // Note: this can be done in a loop if waiting for
            //        more than one occurrence
            Console.WriteLine(
              "Open an application (notepad.exe) to trigger an event.");
            ManagementBaseObject e = watcher.WaitForNextEvent();
            log.Debug(e.GetText(TextFormat.Mof ));
            ManagementBaseObject target = (ManagementBaseObject)e["TargetInstance"];
            Object targetName = target["Name"];
            Object targetPath = target["ExecutablePath"];
            //Display information from the event
            log.Info(
                "Process {0} has been created, path is: " + targetName + ", " + targetPath);

            //Cancel the subscription
            watcher.Stop();
        }
开发者ID:HwangBae,项目名称:hoo-eye-relaxant,代码行数:33,代码来源:EventWatcherPolling.cs

示例4: DriveService

		public DriveService()
		{
			// Bind to local machine
			var options = new ConnectionOptions { EnablePrivileges = true };
			var scope = new ManagementScope(@"root\CIMV2", options);

			try
			{
				var query = new WqlEventQuery
				{
					EventClassName = "__InstanceModificationEvent",
					WithinInterval = TimeSpan.FromSeconds(1),
					Condition = @"TargetInstance ISA 'Win32_LogicalDisk' and TargetInstance.DriveType = 5" // DriveType - 5: CDROM
				};

				this.watcher = new ManagementEventWatcher(scope, query);

				// register async. event handler
				this.watcher.EventArrived += this.HandleDiscEvent;
				this.watcher.Start();
			}
			catch (Exception e)
			{
				System.Diagnostics.Debug.WriteLine(e.Message);
			}
		}
开发者ID:Runcy,项目名称:VidCoder,代码行数:26,代码来源:DriveService.cs

示例5: Start

        public void Start(PagesPrinted callback)
        {
            Printed += callback;

            try
            {

                ManagementScope scope;

                if (!ComputerName.Equals("localhost", StringComparison.OrdinalIgnoreCase))
                {
                    var conn = new ConnectionOptions();
                    conn.Username = "";
                    conn.Password = "";
                    conn.Authority = "ntlmdomain:DOMAIN";
                    scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), conn);
                }
                else
                {
                    scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), null);
                }
                scope.Connect();

                _watcher = new ManagementEventWatcher(scope, new EventQuery(WmiQuery));
                _watcher.EventArrived += new EventArrivedEventHandler(this.WmiEventHandler);
                _watcher.Start();

            }
            catch (Exception e)
            {
                Console.WriteLine("Exception {0} Trace {1}", e.Message, e.StackTrace);
            }
        }
开发者ID:wortexx,项目名称:Footprint,代码行数:33,代码来源:PrintingMonitor.cs

示例6: ProcessObserver

 public ProcessObserver()
 {
     watcher = new ManagementEventWatcher();
         watcher.Query = new WqlEventQuery("__InstanceCreationEvent", new TimeSpan(0, 0, 1), "TargetInstance isa \"Win32_Process\""); ;
         watcher.EventArrived += new EventArrivedEventHandler(OnProcessStarted);
         watcher.Start();
 }
开发者ID:308465570,项目名称:FFXIV-Zodiac-Glass,代码行数:7,代码来源:ProcessObserver.cs

示例7: Init

        private void Init()
        {
            battlefieldIsRunning = false;
            ShowStatus();

            // Hook up to the Application Started events
            startWatch = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace"));
            startWatch.EventArrived += new EventArrivedEventHandler(startWatch_EventArrived);
            try
            {
                startWatch.Start();
            }
            catch (Exception)
            {
                MessageBox.Show("Can't start the Process-Monitor! Are you running as admin?");
                return;
            }

            // Hoop up to the Application closed events
            stopWatch = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStopTrace"));
            stopWatch.EventArrived += new EventArrivedEventHandler(stopWatch_EventArrived);            
            try
            {
                stopWatch.Start();
            }
            catch (Exception)
            {
                MessageBox.Show("Can't start the Process-Monitor! Are you running as admin?");
            }
        }
开发者ID:MarkusKgit,项目名称:Battlefield-Monitor,代码行数:30,代码来源:MainForm.cs

示例8: AddUSBEventWatcher

        public Boolean AddUSBEventWatcher(EventArrivedEventHandler usbInsertHandler, EventArrivedEventHandler usbRemoveHandler, TimeSpan withinInterval)
        {
            try
            {
                ManagementScope Scope = new ManagementScope("root\\CIMV2");
                Scope.Options.EnablePrivileges = true;

                if (usbInsertHandler != null)
                {
                    WqlEventQuery InsertQuery = new WqlEventQuery("__InstanceCreationEvent", withinInterval, "TargetInstance isa 'Win32_USBControllerDevice'");
                    insertWatcher = new ManagementEventWatcher(Scope, InsertQuery);
                    insertWatcher.EventArrived += usbInsertHandler;
                    insertWatcher.Start();
                }

                if (usbRemoveHandler != null)
                {
                    WqlEventQuery RemoveQuery = new WqlEventQuery("__InstanceDeletionEvent", withinInterval, "TargetInstance isa 'Win32_USBControllerDevice'");
                    removeWatcher = new ManagementEventWatcher(Scope, RemoveQuery);
                    removeWatcher.EventArrived += usbRemoveHandler;
                    removeWatcher.Start();
                }
                return true;
            }
            catch (Exception)
            {
                RemoveUSBEventWatcher();
                return false;
            }
        }
开发者ID:jasonhsieh1984,项目名称:usb-rs232-Communication,代码行数:30,代码来源:WMIUsbWatcher.cs

示例9: ProcessWatcher

        public ProcessWatcher(TaskScheduler scheduler, params string[] processNames)
        {
            Scheduler = scheduler;

            foreach (var pname in processNames) {
                var invariant = Path.GetFileNameWithoutExtension(pname).ToLowerInvariant();
                ProcessNames.Add(invariant);

                foreach (var process in Process.GetProcessesByName(invariant)) {
                    RunningProcessIds.Add(process.Id);
                    NewProcesses.Enqueue(process);
                }
            }

            try {
                var query = new WqlEventQuery(@"SELECT * FROM Win32_ProcessStartTrace");
                Watcher = new ManagementEventWatcher(query);
                Watcher.Options.BlockSize = 1;
                Watcher.EventArrived += new EventArrivedEventHandler(OnEventArrived);
                Watcher.Start();
                WatcherEnabled = true;
            } catch {
                Watcher = null;
                WatcherEnabled = false;

                TimerTask = Scheduler.Start(InitTimer(), TaskExecutionPolicy.RunAsBackgroundTask);
            }
        }
开发者ID:kg,项目名称:shootblues,代码行数:28,代码来源:ProcessWatcher.cs

示例10: PathUtility

        static PathUtility()
        {
            var combinedPath = Path.Combine("a", "b");
            DefaultDirectorySeparator = combinedPath.Substring(1, combinedPath.Length - 2);

            //Insert
            WqlEventQuery q_creation = new WqlEventQuery();
            q_creation.EventClassName = "__InstanceCreationEvent";
            q_creation.WithinInterval = new TimeSpan(0, 0, 2);    //How often do you want to check it? 2Sec.
            q_creation.Condition = @"TargetInstance ISA 'Win32_DiskDriveToDiskPartition'";
            _mweCreation = new ManagementEventWatcher(q_creation);
            _mweCreation.EventArrived += UsbStorageInserted;
            _mweCreation.Start(); // Start listen for events

            //Remove
            WqlEventQuery q_deletion = new WqlEventQuery();
            q_deletion.EventClassName = "__InstanceDeletionEvent";
            q_deletion.WithinInterval = new TimeSpan(0, 0, 2);    //How often do you want to check it? 2Sec.
            q_deletion.Condition = @"TargetInstance ISA 'Win32_DiskDriveToDiskPartition'  ";
            _mweDeletion = new ManagementEventWatcher(q_deletion);
            _mweDeletion.EventArrived += UsbStorageRemoved;
            _mweDeletion.Start(); // Start listen for events

            Storage = _knownStorage;
            UpdateStorage();
        }
开发者ID:ApocalypticOctopus,项目名称:Apocalyptic.Utilities.Net,代码行数:26,代码来源:PathUtility.cs

示例11: Main

        static void Main(string[] args)
        {
            var scope = new ManagementScope();
            scope.Path.NamespacePath = WmiConstants.Namespace;

            var createdWatcher = new ManagementEventWatcher(scope, new WqlEventQuery(WmiConstants.TaskCreatedQuery));
            var changedWatcher = new ManagementEventWatcher(scope, new WqlEventQuery(WmiConstants.TaskChangedQuery));
            var removedWatcher = new ManagementEventWatcher(scope, new WqlEventQuery(WmiConstants.TaskRemovedQuery));

            createdWatcher.EventArrived += ObjectCreated_EventArrived;
            changedWatcher.EventArrived += ObjectChanged_EventArrived;
            removedWatcher.EventArrived += ObjectRemoved_EventArrived;

            try
            {
                createdWatcher.Start();
                changedWatcher.Start();
                removedWatcher.Start();

                Console.WriteLine("Press Any Key to Exit");
                Console.WriteLine();
                Console.Read();
            }
            finally
            {
                if (createdWatcher != null)
                    createdWatcher.Stop();

                if (changedWatcher != null)
                    changedWatcher.Stop();

                if (removedWatcher != null)
                    removedWatcher.Stop();
            }
        }
开发者ID:NickSchweitzer,项目名称:WmiDemo,代码行数:35,代码来源:Program.cs

示例12: StartDetection

        /// <summary>
        /// The start detection.
        /// </summary>
        /// <param name="action">
        /// The detection Action.
        /// </param>
        public void StartDetection(Action action)
        {
            ThreadPool.QueueUserWorkItem(
                delegate
                {
                    this.detectionAction = action;

                    var options = new ConnectionOptions { EnablePrivileges = true };
                    var scope = new ManagementScope(@"root\CIMV2", options);

                    try
                    {
                        var query = new WqlEventQuery
                        {
                            EventClassName = "__InstanceModificationEvent",
                            WithinInterval = TimeSpan.FromSeconds(1),
                            Condition = @"TargetInstance ISA 'Win32_LogicalDisk' and TargetInstance.DriveType = 5" // DriveType - 5: CDROM
                        };

                        this.watcher = new ManagementEventWatcher(scope, query);
                        this.watcher.EventArrived += this.WatcherEventArrived;
                        this.watcher.Start();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                });
        }
开发者ID:GTRsdk,项目名称:HandBrake,代码行数:35,代码来源:DriveDetectService.cs

示例13: ChooseForm

        public ChooseForm ()
        {
            InitializeComponent ();

            processView.ListViewItemSorter = new ProcessViewItemComparer ();
            usbDevView.ListViewItemSorter = new DeviceViewItemComparer ();

            processViewUpdater = new ProcessViewUpdater (processView);
            usbViewUpdater = new UsbViewUpdater (usbDevView);

            WqlEventQuery startQuery = new WqlEventQuery ();
            startQuery.EventClassName = "Win32_ProcessStartTrace";

            WqlEventQuery stopQuery = new WqlEventQuery ();
            stopQuery.EventClassName = "Win32_ProcessStopTrace";

            ManagementEventWatcher w = new ManagementEventWatcher (startQuery);
            w.EventArrived += new EventArrivedEventHandler (ProcessEventArrived);
            w.Start();
            processStartWatcher = w;

            w = new ManagementEventWatcher (stopQuery);
            w.EventArrived += new EventArrivedEventHandler (ProcessEventArrived);
            w.Start ();
            processStopWatcher = w;
        }
开发者ID:SayHalou,项目名称:ospy,代码行数:26,代码来源:ChooseForm.cs

示例14: SendLogEntry

        void SendLogEntry(WmiTraceListener listener,
                          LogEntry logEntry)
        {
            ManagementScope scope = new ManagementScope(@"\\." + wmiPath);
            scope.Options.EnablePrivileges = true;

            StringBuilder sb = new StringBuilder("SELECT * FROM ");
            sb.Append("LogEntryV20");
            string query = sb.ToString();
            EventQuery eq = new EventQuery(query);

            using (ManagementEventWatcher watcher = new ManagementEventWatcher(scope, eq))
            {
                watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
                watcher.Start();

                LogSource source = new LogSource("notfromconfig", SourceLevels.All);
                source.Listeners.Add(listener);
                source.TraceData(TraceEventType.Error, 1, logEntry);

                BlockUntilWMIEventArrives();

                watcher.Stop();
            }
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:25,代码来源:WMIListenerFixture.cs

示例15: AddInsertUSBHandler

 private void AddInsertUSBHandler()
 {
     WqlEventQuery query;
     ManagementScope scope = new ManagementScope("root\\CIMV2");
     scope.Options.EnablePrivileges = true;
     insertUSBWatcher = null;
     try
     {
         query = new WqlEventQuery();
         query.EventClassName = "__InstanceCreationEvent";
         query.WithinInterval = new TimeSpan(0, 0, 3);
         query.Condition = "TargetInstance ISA 'Win32_USBControllerdevice'";
         insertUSBWatcher = new ManagementEventWatcher(scope, query);
         insertUSBWatcher.EventArrived += USBInserted;
         insertUSBWatcher.Start();
     }
     catch(Exception e)
     {
         if (insertUSBWatcher != null)
         {
             insertUSBWatcher.Stop();
         }
         throw e;
     }
 }
开发者ID:sr3dna,项目名称:big5sync,代码行数:25,代码来源:DeviceWatcher.cs


注:本文中的System.Management.ManagementEventWatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。