473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

sd card detection(Win32_PhysicalMedia)

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

Nov 17 '05 #1
0 2933

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pete Davis | last post by:
I'm trying to figure out how to distinguish a CD drive from a DVD drive. I thought it would be as simple as using WMI, but the properties that would distinguish between the 2 don't seem to exist...
14
by: Lauren Wilson | last post by:
Discovered this interesting comment on MSDN: "To programmatically obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation (WMI)...
12
by: Krunoslav Ostrouska | last post by:
How can i write on specifyed sector on a multimedia card? I must go round file system and write/read direct. C# VS2003 Thanks Kruno
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.