HighTechTalks DotNet Forums  

Problem with WMI Event Notification

Dotnet Framework (WMI) microsoft.public.dotnet.framework.wmi


Discuss Problem with WMI Event Notification in the Dotnet Framework (WMI) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
=?Utf-8?B?VG9tIFByYWlzb24=?=
 
Posts: n/a

Default Problem with WMI Event Notification - 06-13-2007 , 01:20 AM






I am using WMI to monitor few critical processes running in my server. I
subscribe to instance deletion event and check whether the process is my
processes and send a mail. But it happens that sometimes instancedeletion
event is called for all the processes in my system when they are still
running. After few mins or seconds the creationevent is called for all these
processes. I dont know why this happens. Could anyone tell me why it happens.
the code is as follows

string scope = @"\\.\root\CIMV2";
ManagementScope MgtScope = new ManagementScope(scope);
// create the wql query to subscribe to a process deletion
event
WqlEventQuery query =
new WqlEventQuery("__InstanceDeletionEvent",
new TimeSpan(0, 0, 10),
"TargetInstance isa \"Win32_Process\"");

// Initialize an event watcher and subscribe to events
// that match this query
//for deletion event
ManagementEventWatcher watcherDel =
new ManagementEventWatcher() ;
watcherDel.Query = query;
watcherDel.Scope = MgtScope;
watcherDel.EventArrived += new
EventArrivedEventHandler(DeletionArrived);
watcherDel.Start();

// for creation event
query = new WqlEventQuery("__InstanceCreationEvent",
new TimeSpan(0, 0, 10),
"TargetInstance isa \"Win32_Process\"");

ManagementEventWatcher watcherCre =
new ManagementEventWatcher();
watcherCre.Query = query;
watcherCre.Scope = MgtScope;
watcherCre.EventArrived += new
EventArrivedEventHandler(CreationArrived);
watcherCre.Start();
Console.ReadLine();
watcherDel.Stop();
watcherDel.Dispose();
watcherCre.Stop();
watcherCre.Dispose();

private void DeletionArrived(object sender, EventArrivedEventArgs e)
{
ManagementBaseObject eventArg =
(ManagementBaseObject)(e.NewEvent["TargetInstance"]);
string ProcessName = eventArg["Name"].ToString();
// check the name with my processes
}


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.