RemoveDrive prepares drives for "Safe Removal" by commandline. It works with drives only but not for other device types.
RemoveDrive DriveSpec: [-l][-h][-b][-i][-s][-w:nnnn]
DriveSpec is the drive to remove, e.g. U: or an NTFS mountpoint as "C:\CardReader\Multi Reader SD"
or . for the current drive
or \ for the drive of the RemoveDrive.exe
or a volume name like \\?\Volume{433619ed-c6ea-11d9-a3b2-806d6172696f}
[-L] loop until success
[-h] show open handles (admin rights required, exprimental, may freeze!)
[-w:nnnn] wait nnnn milliseconds before close
[-s] self delete removedrive.exe
[-b] let Windows show the "Safe To Remove Hardware" balloon tip
[-i] stop Windows indexing service (CiSvc) for a moment if required (admins)
[-d] show debug information
or
RemoveDrive "AnyIdString"
RemoveDrive can be used with all types of drives. Started with -L it tries to remove the drive in an endless loop until success or until canceled.
As result it shows 'success' in green or 'failed' in red.
Sample:
removedrive u: -L
would try to prepare drive U: for safe removal in an endless loop until success.
For drives mounted into NTFS folders the full path of the folder can be used:
removedrive "E:\_CardReader\USB20 CF" -L
Used with multislot-cardreaders it would remove the whole reader, regardless of the given slot. For removing a card only, use my EjectMedia tool, see below.
Instead the drive letter one of the drive's device ID strings can be used. The friendly name can be used as "Corsair Flash Voyager" or the hardware ID of the drive, like USB\VID_1234&PID_5678...
Wildcards can be used here. E.g. RemoveDrive *Flash* to remove the first drive with 'Flash' in its device name.
RemoveDrive can be started from the drive to remove. Because a running EXE on a drive prevents a drive being prepared for safe removal it creates a temporary, self deleing copy and starts it with the same parameters. To be drive letter independent, use . instead a drive letter. The current drive is removed then. To remove the drive of the RemoveDrive.exe use \ as drive.
If the removal fails then someone still accesses the drive. This can be something banal like an open Word document or an mounted TrueCrypt container or some kind of monitoring tool like a virus scanner. A network share on the drive that has been used makes the removal fail too...
By means of SysInternals
ProcessExplorer you might be able to discover which program holds an open handle to the drive. After starting it go to 'Find' -> 'Find Handle or DLL', enter the drive letter like X:\ or a part of the DOS device name like 'Harddisk3' and search. You get the 'DOS device name' by means of my
ListUsbDrives or
ListDosDevices.
Download: removedrive.zip
Last update: 2 August 2009
For programmers I've made a demo project which shows the essentials:
How to prepare an USB drive for safe removal
An alternative to the Windows tray icon is "HotSwap":
http://mysite.verizon.net/kaakoon/hotswap/index_enu.htm
|