Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Safely removing hardware

51 views
Skip to first unread message

cart...@gmail.com

unread,
Jan 27, 2007, 1:10:17 PM1/27/07
to
I am working on a program that reads data from a removable device (USB
Stick) that the user will insert into the computer and then when the
data is removed, will need to remove the media. In the system tray,
there is the icon/tool to "Safely Remove Hardware". How do I do that
programmatically? I am working in C#, so if I can avoid dropping to
the API level, that would be great, but with 10+ years of C/C++
experence, WinAPI level examples work, too!

Don Burn

unread,
Jan 27, 2007, 1:18:31 PM1/27/07
to
You need the Setup api's from the DDK/WDK. Get the WDK and look at the
DevCon sample for information on how to do it.

--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply


<cart...@gmail.com> wrote in message
news:1169921417....@m58g2000cwm.googlegroups.com...

cart...@gmail.com

unread,
Jan 27, 2007, 1:38:06 PM1/27/07
to
On Jan 27, 1:18 pm, "Don Burn" <b...@stopspam.windrvr.com> wrote:
> You need the Setup api's from the DDK/WDK. Get the WDK and look at the
> DevCon sample for information on how to do it.

Don,

It looks like the WDK is not a free download, am I correct? If not,
any thoughts on where to go find it? This is the link I found:

http://www.microsoft.com/whdc/devtools/wdk/betawdk.mspx

Don Burn

unread,
Jan 27, 2007, 1:44:50 PM1/27/07
to
Actually it is free, you just have to follow the directions. I know the
page says Beta, but it now gives you the release version. Alternatively,
if you can find the last DDK Build 3790.1830 that should work fine also.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply


<cart...@gmail.com> wrote in message
news:1169923086....@m58g2000cwm.googlegroups.com...

Uwe Sieber

unread,
Jan 27, 2007, 2:50:56 PM1/27/07
to

I've shown this in user mode in a sample project:
http://www.codeproject.com/system/RemoveDriveByLetter.asp

The page needs an update because of some new findings.

CM_Query_And_Remove_SubTree requires admin previleges, while
CM_Request_Device_Eject does not. Today I've seen that Vista
redetected an USB hard disk immediately after using
CM_Query_And_Remove_SubTree successfully. It did not happen
with CM_Request_Device_Eject.

If you want XP show the "it's save now" balloon, then use
NULL/0 for the veto params. An additional effect is, that
XP doesn't play the removal sound then when the device is
unplugged. Quite strange...


Greetings from Germany

Uwe

Arkady Frenkel

unread,
Jan 28, 2007, 3:18:09 AM1/28/07
to
If you need only devcon , take it from
http://support.microsoft.com/kb/311272
Arkady

"Don Burn" <bu...@stopspam.windrvr.com> wrote in message
news:OCPB8MkQ...@TK2MSFTNGP05.phx.gbl...

Uwe Sieber

unread,
Jan 28, 2007, 2:15:59 PM1/28/07
to
Uwe Sieber wrote:
> cart...@gmail.com wrote:
>> I am working on a program that reads data from a removable device (USB
>> Stick) that the user will insert into the computer and then when the
>> data is removed, will need to remove the media. In the system tray,
>> there is the icon/tool to "Safely Remove Hardware". How do I do that
>> programmatically? I am working in C#, so if I can avoid dropping to
>> the API level, that would be great, but with 10+ years of C/C++
>> experence, WinAPI level examples work, too!
>
> Today I've seen that Vista
> redetected an USB hard disk immediately after using
> CM_Query_And_Remove_SubTree successfully.


With the flag CM_REMOVE_NO_RESTART the redetection does not happen.

Uwe

Pavel A.

unread,
Jan 31, 2007, 2:10:00 PM1/31/07
to
> Uwe Sieber wrote:
> >
> > Today I've seen that Vista
> > redetected an USB hard disk immediately after using
> > CM_Query_And_Remove_SubTree successfully.
>
> With the flag CM_REMOVE_NO_RESTART the redetection does not happen.
>
> Uwe
>

An interesting finding.
Doron Holan (MS) explained that in Vista, behavior of PnP is more
"agressive" so that it immediately redetects removed devices and this
results in immediate installation of the best ranked driver found.

If this flag gets the old behavior, can Device Manager use it ?

Too late to vote for this feature for Vista SP1?

--PA

0 new messages