tags:

views:

1026

answers:

2

hi, i need to connect and disconnect usb progrmmatically , that is i have inserted the usb device i need to transfer the file using C#,.net application ,the application will watch the particular folder and transfer the file from that folder to usb drive. i need to disconnect the usb after the file is transfered and connect the usb when needed..without unplug and replug

pls guide me with code or is there any dll available.

Main thing NOTE NOTE ::::Without unplug and replug the usb

thanks in advance .....

A: 

I'm not exactly sure, but it can be done. In Linux, I've experienced certain situations where power is disconnected to a device programmatically. The kernel usually does this if the connected USB device is exhibiting too many errors. So, it should be possible to do this even in Windows. You may need to write your own external DLL to do it though.

sybreon
+2  A: 

If your goal is to make a certain disk volume unavailable while you're not using it, a more sensible approach might be to use the volume management APIs, e.g. by using the IOCTL_VOLUME_OFFLINE control code. (I'm assuming that you know which drive letter belongs to your USB disk.)

Alternatively, you can disable and enable the volume device programatically with the CfgMgr API -- same as right-clicking the volume in Device Manager and choosing Disable would do.

The latter option might require a privileged user account.

Ilya