tags:

views:

1489

answers:

5

How do you programmatically eject(safely remove) an USB mass storage device in Windows (XP)?

+1  A: 

You could spawn a process and use a command line tool. This would also work from other languages such as java where calling the Win32 api is harder.

johnstok
Not quite what I was looking for, but thanks anyway :).Maybe their's license do not forbids disassembly their code...
botismarius
+2  A: 

Here is a project (with source code) that appears to have figured it out.

EBGreen
+1  A: 

There is an article about it at CodeProject: http://www.codeproject.com/KB/system/usbeject.aspx

Seems to do the trick.

/johan/

idstam
+2  A: 

In autoit, you have a script which does just that.

It basically comes from this Microsoft article and uses kernel32.dll DeviceIoControl function

Of course, this question appears to be a duplicate of Safe remove USB-Drive using Win32 API?, which gives other solutions

VonC
Nice. I should try this one.
botismarius
botismarius
A: 

codeproject sample is just a poor copy of MS sample...