Reputation: 23
I am not familiar with USB and I am not able (with delphi) to improve my software with a self disconnect USB function.
The program is on and runs from a USB memory drive (e. g. F:/) and when it stop what I try to do is to auto eject the device.
I also tried to do a .bat file that runs a program that disable the USB device. If this .bat file is launched from local drive (C:/) everything is ok, but if this .bat file is launched from USB stick (F:/) it fails.
Here the link where I got the information:
How can i remove a USB flash disk programmatically using delphi?
Any suggestion in delphi?
Upvotes: 0
Views: 420
Reputation: 613592
The problem you have is the the process you are executing was run from thee drive that you are ejecting. The executable file is locked and that prevents your drive from being ejected.
It is clear what you need to do. You must make sure that no files on the drive are locked. That means that you must terminate your process. You then need another process, run from a different drive, to perform the ejection. Do the following:
CreateProcess
. Pass an inheritable handle for process A to process B on the command line. Upvotes: 2