PC Review


Reply
Thread Tools Rate Thread

Detecting memory card/USB device insertion - how to?

 
 
Chris Lewis
Guest
Posts: n/a
 
      25th Nov 2005
Hi,

I want my app to respond to attachment of a memory card (SD) and/or a
particular type of USB device to a client PC. Both devices have on them the
same file/directory structure - i.e. a directory structure recognisable to
my application.

What I would like to do is have my .NET Windows Form app start automatically
(if it is not already running) when either device is attached to the
machine, and have the files pre-selected in an explorer-like window for the
user to take further action with. Adobe Elements does this, for example,
when I attach my Compact Flash card to my PC - it seems to use a Windows
Service called 'Adobe Active File Monitor' that runs constantly in the
background.

Any ideas how to do this, or better still any code out there that already
does this? I don't think the .NET FileSystemWatcher will work for removable
devices, so I suspect that a bespoke polling component is needed. If so, how
is it best to detect the presence or otherwise of removable drives?

Thanks,

Chris


 
Reply With Quote
 
 
 
 
S.M. Altaf [MVP]
Guest
Posts: n/a
 
      25th Nov 2005
Hi, Go through this:

http://www.codeproject.com/dotnet/de...umemonitor.asp

HTH
--------------------------------------------------------------------------------
All that glitters has a high refractive index.
www.mendhak.com


"Chris Lewis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I want my app to respond to attachment of a memory card (SD) and/or a
> particular type of USB device to a client PC. Both devices have on them
> the same file/directory structure - i.e. a directory structure
> recognisable to my application.
>
> What I would like to do is have my .NET Windows Form app start
> automatically (if it is not already running) when either device is
> attached to the machine, and have the files pre-selected in an
> explorer-like window for the user to take further action with. Adobe
> Elements does this, for example, when I attach my Compact Flash card to my
> PC - it seems to use a Windows Service called 'Adobe Active File Monitor'
> that runs constantly in the background.
>
> Any ideas how to do this, or better still any code out there that already
> does this? I don't think the .NET FileSystemWatcher will work for
> removable devices, so I suspect that a bespoke polling component is
> needed. If so, how is it best to detect the presence or otherwise of
> removable drives?
>
> Thanks,
>
> Chris
>
>



 
Reply With Quote
 
Chris Lewis
Guest
Posts: n/a
 
      25th Nov 2005
Thanks for the link. I have tried running this on my XP SP2 machine, and
nothing seemed to happen (i.e. no events were fired at all) when I attached
a CompactFlash card via a multi-card USB reader? Any ideas?

Thanks,

Chris

"S.M. Altaf [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi, Go through this:
>
> http://www.codeproject.com/dotnet/de...umemonitor.asp
>
> HTH
> --------------------------------------------------------------------------------
> All that glitters has a high refractive index.
> www.mendhak.com
>
>
> "Chris Lewis" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi,
>>
>> I want my app to respond to attachment of a memory card (SD) and/or a
>> particular type of USB device to a client PC. Both devices have on them
>> the same file/directory structure - i.e. a directory structure
>> recognisable to my application.
>>
>> What I would like to do is have my .NET Windows Form app start
>> automatically (if it is not already running) when either device is
>> attached to the machine, and have the files pre-selected in an
>> explorer-like window for the user to take further action with. Adobe
>> Elements does this, for example, when I attach my Compact Flash card to
>> my PC - it seems to use a Windows Service called 'Adobe Active File
>> Monitor' that runs constantly in the background.
>>
>> Any ideas how to do this, or better still any code out there that already
>> does this? I don't think the .NET FileSystemWatcher will work for
>> removable devices, so I suspect that a bespoke polling component is
>> needed. If so, how is it best to detect the presence or otherwise of
>> removable drives?
>>
>> Thanks,
>>
>> Chris
>>
>>

>
>



 
Reply With Quote
 
=?Utf-8?B?YmFsbWVyY2g=?=
Guest
Posts: n/a
 
      28th Nov 2005
Try what one of the comments on that site suggests for that article:

"The reason why Riul's solution doesn't work for anything except CD/DVD
drives is the line
if(lBroadcastHeader.Type==DeviceType.Volume)
in _DeviceVolumeMonitor.WndProc(), file DeviceVolumeMonitor.cs line 108.

Remove/comment the if and always trigger the events to also get
notifications for USB or Network devices."

Chris

"Chris Lewis" wrote:

> Thanks for the link. I have tried running this on my XP SP2 machine, and
> nothing seemed to happen (i.e. no events were fired at all) when I attached
> a CompactFlash card via a multi-card USB reader? Any ideas?
>
> Thanks,
>
> Chris
>
> "S.M. Altaf [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi, Go through this:
> >
> > http://www.codeproject.com/dotnet/de...umemonitor.asp
> >
> > HTH
> > --------------------------------------------------------------------------------
> > All that glitters has a high refractive index.
> > www.mendhak.com
> >
> >
> > "Chris Lewis" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> Hi,
> >>
> >> I want my app to respond to attachment of a memory card (SD) and/or a
> >> particular type of USB device to a client PC. Both devices have on them
> >> the same file/directory structure - i.e. a directory structure
> >> recognisable to my application.
> >>
> >> What I would like to do is have my .NET Windows Form app start
> >> automatically (if it is not already running) when either device is
> >> attached to the machine, and have the files pre-selected in an
> >> explorer-like window for the user to take further action with. Adobe
> >> Elements does this, for example, when I attach my Compact Flash card to
> >> my PC - it seems to use a Windows Service called 'Adobe Active File
> >> Monitor' that runs constantly in the background.
> >>
> >> Any ideas how to do this, or better still any code out there that already
> >> does this? I don't think the .NET FileSystemWatcher will work for
> >> removable devices, so I suspect that a bespoke polling component is
> >> needed. If so, how is it best to detect the presence or otherwise of
> >> removable drives?
> >>
> >> Thanks,
> >>
> >> Chris
> >>
> >>

> >
> >

>
>
>

 
Reply With Quote
 
Chris Lewis
Guest
Posts: n/a
 
      29th Nov 2005
Thanks for this Chris.

I went back to the code with your suggestion, but found that commenting the
line you mention made no difference. However, I commented out line 111
instead ('if((lVolume.Flags & (int)VolumeFlags.Media)!=0)') and this did
work, but only for a removable device (an SD card) plugged directly into the
SD slot on my laptop. Devices plugged into an attached USB multi-card reader
were not picked up.

I have achieved what I need to do using the following article buried in the
MSDN help for VS2003 - article called 'Drives and Directories and Files! Oh
my!' (MSDN URL
'ms-help://MS.VSCC.2003/MS.MSDNQTR.2005OCT.1033/dnadvnet/html/vbnet07232002.htm')
which demos use of the Windows Scripting Host COM object to obtain device
and directory info from all connected devices - I have written some code
based on the article to poll the connected drives periodically on a
dedicated thread and raise events when drives are inserted or removed, and
it works exactly as I need it to - including using the USB card reader.

Chris

"balmerch" <(E-Mail Removed)> wrote in message
news:29915D94-EC2F-430F-BA48-(E-Mail Removed)...
> Try what one of the comments on that site suggests for that article:
>
> "The reason why Riul's solution doesn't work for anything except CD/DVD
> drives is the line
> if(lBroadcastHeader.Type==DeviceType.Volume)
> in _DeviceVolumeMonitor.WndProc(), file DeviceVolumeMonitor.cs line 108.
>
> Remove/comment the if and always trigger the events to also get
> notifications for USB or Network devices."
>
> Chris
>
> "Chris Lewis" wrote:
>
>> Thanks for the link. I have tried running this on my XP SP2 machine, and
>> nothing seemed to happen (i.e. no events were fired at all) when I
>> attached
>> a CompactFlash card via a multi-card USB reader? Any ideas?
>>
>> Thanks,
>>
>> Chris
>>
>> "S.M. Altaf [MVP]" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Hi, Go through this:
>> >
>> > http://www.codeproject.com/dotnet/de...umemonitor.asp
>> >
>> > HTH
>> > --------------------------------------------------------------------------------
>> > All that glitters has a high refractive index.
>> > www.mendhak.com
>> >
>> >
>> > "Chris Lewis" <(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed)...
>> >> Hi,
>> >>
>> >> I want my app to respond to attachment of a memory card (SD) and/or a
>> >> particular type of USB device to a client PC. Both devices have on
>> >> them
>> >> the same file/directory structure - i.e. a directory structure
>> >> recognisable to my application.
>> >>
>> >> What I would like to do is have my .NET Windows Form app start
>> >> automatically (if it is not already running) when either device is
>> >> attached to the machine, and have the files pre-selected in an
>> >> explorer-like window for the user to take further action with. Adobe
>> >> Elements does this, for example, when I attach my Compact Flash card
>> >> to
>> >> my PC - it seems to use a Windows Service called 'Adobe Active File
>> >> Monitor' that runs constantly in the background.
>> >>
>> >> Any ideas how to do this, or better still any code out there that
>> >> already
>> >> does this? I don't think the .NET FileSystemWatcher will work for
>> >> removable devices, so I suspect that a bespoke polling component is
>> >> needed. If so, how is it best to detect the presence or otherwise of
>> >> removable drives?
>> >>
>> >> Thanks,
>> >>
>> >> Chris
>> >>
>> >>
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto-detecting SD card insertion Noble Bell Microsoft Dot NET Compact Framework 6 13th Mar 2008 10:22 AM
Computer not detecting memory card =?Utf-8?B?dGFuamE=?= Windows XP General 1 28th Oct 2006 06:12 AM
Detecting memory card insertion/removal Michael Microsoft Dot NET Compact Framework 6 27th Jul 2005 01:13 PM
Install Application to a memory card on the Device? =?Utf-8?B?ZWxlbmE=?= Microsoft Dot NET Compact Framework 6 2nd Apr 2005 08:08 PM
PCI Combo card not detecting external device =?Utf-8?B?U0FuZHJldw==?= Windows XP Help 1 28th Feb 2004 01:56 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:45 AM.