hi
i have a doubt on WMI related thing
i wanto write a C# code which detects whenever memory card
like sd card or cf card is inserted or removed
i m using WMI for tht purpose
i m using the 'Win32_PhysicalMedia' and mediatype as 28 which indicates
memory card
HERES A PART OF MY CODE
howver the event is not getting fired on inseertion of card..am i
going
wrong??
public static void Main()
{
ManagementEventWatcher objCardWatcher=null;
objCardWatcher =EventDetection.GetWatcher("__InstanceCreationEven t",
"TargetInstance ISA 'Win32_PhysicalMedia' and
TargetInstance.MediaType=28")
;
//subscribes to an event based on event query
objCardWatcher.EventArrived += new
EventArrivedEventHandler(objEventDetection.CardEve ntRaised);
objCardWatcher.Start();
}
public static ManagementEventWatcher GetWatcher(string
WatcherType,string
strQuery)
{
string objWatcherType = WatcherType;
//queries for events occuring at USB Port
WqlEventQuery objWqlEventQuery = new
WqlEventQuery(objWatcherType,new
TimeSpan(0,0,3),strQuery);
// Bind to local machine
ManagementScope objScope = new ManagementScope("root\\CIMV2");
objScope.Options.EnablePrivileges = true;
ManagementEventWatcher objEventWatcher = new
ManagementEventWatcher(objScope, objWqlEventQuery);
return objEventWatcher;
}
public void CardEventRaised(object sender, EventArrivedEventArgs e)
{
try
{
Console.WriteLine("CARD EVENT IS raised");
// // Get the Event object and display it
// PropertyData objPropertyData;
//
// if((objPropertyData = e.NewEvent.Properties["TargetInstance"] )
!=
null )
// {
// ManagementBaseObject objBaseObject = objPropertyData.Value as
ManagementBaseObject;
//
// }
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
is there any other way of doing
cause this is not working..
i tried posting the query on the WMI site but dint get reply
PLEASE HELP!!!!!!!!!
thanx for ur valuable time