473,836 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c#.net detect media card insertion

hi
can anyone help me with this
i want to write a code in c#.net which detects usb storage and media
card insertion
can anyone help me with this??
thanx

Nov 17 '05 #1
4 5818
sanjana,

Your problem will be solved by the computer, so why try bother with
programming, unless making your own computer?

C# isn't meant to solve your kind of problem, its for software
devolopment!

Visually Seen #

Nov 17 '05 #2
me
/*
* A simple app to demonstrates how to monitor the UsbControllerDe vice for
* the arrival of creation/operation events
* Downloaded from www.publicjoe.co.uk
*
* This software is provided 'as-is', without any express or implied
warranty.
* In no event will the author(s) be held liable for any damages arising
from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely.
*/

using System;
using System.Manageme nt;

class WMIEvent
{
public static void Main()
{
WMIEvent we = new WMIEvent();
ManagementEvent Watcher w= null;
WqlEventQuery q;
ManagementOpera tionObserver observer = new
ManagementOpera tionObserver();

// Bind to local machine
ManagementScope scope = new ManagementScope ("root\\CIMV2") ;
scope.Options.E nablePrivileges = true; //set required privilege

try
{
q = new WqlEventQuery() ;
q.EventClassNam e = "__InstanceOper ationEvent";
q.WithinInterva l = new TimeSpan(0,0,3) ;
q.Condition = @"TargetInstanc e ISA 'Win32_DiskDriv e' ";

w = new ManagementEvent Watcher(scope, q);
w.EventArrived += new EventArrivedEve ntHandler(we.Di skEventArrived) ;
w.Start();

Console.ReadLin e(); // block main thread for test purposes
}
catch(Exception e)
{
Console.WriteLi ne(e.Message);
}
finally
{
w.Stop();
}
}

public void DiskEventArrive d(object sender, EventArrivedEve ntArgs e)
{
//Get the Event object and display its properties (all)
foreach(Propert yData pd in e.NewEvent.Prop erties)
{
ManagementBaseO bject mbo = null;

if(( mbo = pd.Value as ManagementBaseO bject) != null)
{
Console.WriteLi ne("--------------Properties------------------");

foreach(Propert yData prop in mbo.Properties)
Console.WriteLi ne("{0} - {1}", prop.Name, prop.Value);
}
}
}
}"sanjana" <su****@gmail.c om> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
hi
can anyone help me with this
i want to write a code in c#.net which detects usb storage and media
card insertion
can anyone help me with this??
thanx

Nov 17 '05 #3
There are many reasons why you would want to detect this in a program, maybe
you want to wait until a USB is inserted into the computer and then retrieve
all the images of the USB, there are a thousand and one reasons why.

C# can definitely be used to solve this kind of problem.

"Visually Seen #" wrote:
sanjana,

Your problem will be solved by the computer, so why try bother with
programming, unless making your own computer?

C# isn't meant to solve your kind of problem, its for software
devolopment!

Visually Seen #

Nov 17 '05 #4
hi i tried th following to detect if anything is connected at the usb
port..dint work

class usbdetect
{
public static void Main()
{
usbdetect we = new usbdetect();
ManagementEvent Watcher w= null;
WqlEventQuery q;
ManagementOpera tionObserver observer = new
ManagementOpera tionObserver();
// Bind to local machine
ManagementScope scope = new
ManagementScope ("root\\CIMV2") *;
scope.Options.E nablePrivileges = true; //sets
required privilege
try
{
q = new WqlEventQuery() ;
q.EventClassNam e =
"__InstanceOper ationEvent";
q.WithinInterva l = new TimeSpan(0,0,3) ;

q.Condition = @"TargetInstanc e ISA
'Win32_USBContr oller'";
Console.WriteLi ne(q.QueryStrin *g);
w = new ManagementEvent Watcher(scope,
q);
w.EventArrived += new
EventArrivedEve ntHandler(we.Us *bEventArrived) ;
w.Start();
Console.ReadLin e(); // block main
thread for test purposes
}
catch(Exception e)
{
Console.WriteLi ne(e.Message);
}
finally
{
w.Stop();
}
}
public void UsbEventArrived (object sender,
EventArrivedEve ntArgs e)
{
//Get the Event object and display it
foreach(Propert yData pd in
e.NewEvent.Prop erties)
{
ManagementBaseO bject mbo = null;
if(( mbo = pd.Value as
ManagementBaseO bject) != null)
{
foreach(Propert yData prop in
mbo.Properties)
Console.WriteLi ne("{0}
- {1}", prop.Name, prop.Value);
}
}
}
}
but its not working.......? wats the error..it does not detect if
a device is inserted at the usb port..





me wrote:
/*
* A simple app to demonstrates how to monitor the UsbControllerDe vice for
* the arrival of creation/operation events
* Downloaded from www.publicjoe.co.uk
*
* This software is provided 'as-is', without any express or implied
warranty.
* In no event will the author(s) be held liable for any damages arising
from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely.
*/

using System;
using System.Manageme nt;

class WMIEvent
{
public static void Main()
{
WMIEvent we = new WMIEvent();
ManagementEvent Watcher w= null;
WqlEventQuery q;
ManagementOpera tionObserver observer = new
ManagementOpera tionObserver();

// Bind to local machine
ManagementScope scope = new ManagementScope ("root\\CIMV2") ;
scope.Options.E nablePrivileges = true; //set required privilege

try
{
q = new WqlEventQuery() ;
q.EventClassNam e = "__InstanceOper ationEvent";
q.WithinInterva l = new TimeSpan(0,0,3) ;
q.Condition = @"TargetInstanc e ISA 'Win32_DiskDriv e' ";

w = new ManagementEvent Watcher(scope, q);
w.EventArrived += new EventArrivedEve ntHandler(we.Di skEventArrived) ;
w.Start();

Console.ReadLin e(); // block main thread for test purposes
}
catch(Exception e)
{
Console.WriteLi ne(e.Message);
}
finally
{
w.Stop();
}
}

public void DiskEventArrive d(object sender, EventArrivedEve ntArgs e)
{
//Get the Event object and display its properties (all)
foreach(Propert yData pd in e.NewEvent.Prop erties)
{
ManagementBaseO bject mbo = null;

if(( mbo = pd.Value as ManagementBaseO bject) != null)
{
Console.WriteLi ne("--------------Properties------------------");

foreach(Propert yData prop in mbo.Properties)
Console.WriteLi ne("{0} - {1}", prop.Name, prop.Value);
}
}
}
}"sanjana" <su****@gmail.c om> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
hi
can anyone help me with this
i want to write a code in c#.net which detects usb storage and media
card insertion
can anyone help me with this??
thanx


Nov 17 '05 #5

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

Similar topics

0
1392
by: Viper99 | last post by:
Need to detect (receive notification) for the insertion/removal of PCMCIA devices on Windows 2000/XP in a C# .Net application. Was able to do this in ATL COM app using CWnd::OnDeviceChange().
10
25637
by: Ben Xia | last post by:
Is there some way can detect MAC address with PHP? any help will be appreciate. Ben
9
37214
by: Paul Steele | last post by:
I am writing a C# app that needs to periodically poll for cdroms and usb storage device insertions. I've looked at the WMI functions but haven't found anything all that useful. The closest is Win32_DiskDrive, but it doesn't seem to return any information on cdrom devices. I suspect there might be a Win32 API call, but I haven't found any info yet using Google. Is there a way to achieve this in C#?
2
3052
by: FE | last post by:
Hi, I need to create a program that will connect a media stream (a server on the internet - Windows Media format) and then generate an error when : * The stream is ok but there is no sound (for example when someone disconnected the mic) * The stream is ok but there is no more images In these to cases, I imagine the encoding server is still working fine but
3
3898
by: Mike Joyce | last post by:
I am trying to write a portable script that will find removable media, such as compact flash, sd card, usb, etc. drive and then upload files from the media. I want this to be portable so that I can write and maintain one program for both Linux and Windows. Each platform uses different functions so even if I could find two platform dependent functions that would be fine. Basically, I would like to avoid checking fixed disks if possible. If...
1
5598
by: Steve Marshall | last post by:
Hi All, Apologies if this has come up before, but how can I set up something that will notify me when a removeable drive (like a USB drive or CompactFlash card) is inserted into its slot? Ideally I would like some sort of event that would call my code when it happens. The FileSystemWatcher object doesn't seem able to do this, unless I am missing something. Thanks
0
1255
by: Tim Kelley | last post by:
Is there a facility in C# to detect the insertion of an SD or CF card? Thanks
1
2538
by: =?Utf-8?B?Sm9lIE1pbGxlcg==?= | last post by:
I am a developer and a photographer, and I am trying to write a windows service that can recieve a notification that a compact flash card, or an SD card has been insterted into a card reader slot. The card reader is a multi-format (CF/SD/MMC, etc) reader connected to the machine by USB. I want the service to recieve a notification of the card insertion, so it can grab the files, read the EXIF/IPTC data, and process the files (cataloging,...
2
4782
by: lazzypink | last post by:
hi guys! i having a problem in my project which is create a media player and let the user choose the sound card for audio output. Let say i have 2 sound card in my computer, i want to select the sound card to play an audio file. i'm using C# window media player com component. eg. axWindowsMediaPlayer1. your kindly help much much appreciated. Thanks!
0
9825
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10846
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10595
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9379
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6979
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5828
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4021
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.