EjectUSB

EjectUSB
Version 1.6
Designed to be a simple utility to close all programs running from a specified drive or folder and then attempt ejection if a drive was specified. Extended functionality includes flushing the file cache, closing Explorer windows and removing registry entries and Recent Document shortcuts referencing the specified drive or folder.

Documentation and an example configuration file are included in the ZIP. The source code is available as a separate download.

TrueCrypt and combination flash card / flash drives support will be made available via configuration files after sufficient testing has been conducted.

See EjectUSB in action!
» Watch the flash video

Release Version 1.6:
» Download EjectUSB (259 kilobytes, 135103 downloads)
» Source Code (26 kilobytes, 11813 downloads)


Change Log:
Version 1.6
- Bug fix: EjectUSB no longer triggers file access errors on WinXP when run from read-only media when trying to load its hourglass tray icon.
- Bug fix: Sysinternals registry keys are no longer erroneously deleted.

Version 1.5 (161498 downloads)
- Bug fix: EjectUSB's ejection success message will more reliably appear on Vista.
- Bug fix: EjectUSB's ejection success message will only disappear when the ejected drive is unplugged instead of disappearing when any USB device is unplugged.
- Bug fix: EjectUSB will no longer display an error if WMI functions fail.
- Improvement: EjectUSB's ejection success message now displays the ejected drive's name.
- Addition: Added /ini command line argument to allow a settings file to be specified.
- Addition: Added /settings command line argument to display a settings interface window.
- Addition: Included Settings.bat with the download to make adjusting settings easier.
- Change: Modified the manifest information.

Version 1.4 (88989 downloads)
- Bug fix: Graceful program closing no longer only targets programs with a visible window.
- Bug fix: Flushing file buffers can no longer cause ejection to fail.
- Improvement: Dead tray icon cleanup is more resilient and slightly faster.
- Improvement: EjectUSB can now generate its own ejection success message. This will make ejection seem much faster on most computers.
- Addition: Added NoFakedMsg setting to the configuration file format.

Version 1.3 (107575 downloads)
- Bug fix: Program closing on Win9x works again (was broken in 1.2).
- Bug fix: Fixed issues on Win9x when running EjectUSB from a drive's root folder.
- Improvement: Implemented hybrid batch scripting. This provides theorhetical support for TrueCrypt and combination flash card / flash drives as well as conditional operations.
- Improvement: EjectUSB can now interface with EjectMedia.exe to eject flash cards / CDs.
- Improvement: Implemented support for Subst.
- Addition: Added DoNotSubst and NoRedirect settings to the configuration file format.
- Addition: Added /nobat command line argument to disable use of the hybrid batch file (if present). Meant to be used within the hybrid batch file if starting another instance of EjectUSB to prevent infinite loops.

Version 1.2 (4933 downloads)
- Bug fix: Improved handling of relative paths (\ and ..).
- Improvement: Implemented API-based ejection.
- Improvement: Implemented file cache flushing. Requires admin privileges.
- Improvement: EjectUSB can now interface with Sync (from Sysinternals) to flush the file cache (instead of using its own internal file cache flushing function). Requires admin privileges.
- Improvement: Improved command line argument parsing; drive letter or folder path no longer are required at all and no longer must be the first command line argument.
- Improvement: Efficiency improvements related to DLL calls.
- Addition: Added DoNotFlush and NoEjectAPI settings to the configuration file format.
- Change: RemoveDrive.exe is called with the -L switch to loop until successful ejection. This can be aborted by closing the RemoveDrive.exe console window.
- Change: DevEject.exe is now launched hidden.
- Change: Added current version number to EjectUSB.exe version info.

Version 1.1 (3413 downloads)
- Bug fix: Improved ejection capability via EjectUSB's own internal ejection routine.
- Bug fix: Improved command line argument and input parsing for handle.exe; there were some formatting differences between the output on Win9x and WinXP.
- Bug fix: TimeToWait is now a maximum per ''phase'' rather than per program; in rare cases EjectUSB could wait for multiple minutes on closing programs with the default TimeToWait value of 5 (seconds).
- Bug fix: Cleaning up dead tray icons was triggered by faulty criteria; in simple terms, dead tray icon cleanup was occuring when it didn't need to (wasting up to 1 second).
- Improvement: Minor efficiency improvements related to the previous two changes.
- Improvement: EjectUSB can now interface with Unlocker to close open file handles; simply UniExtract the Unlocker installer and put Unlocker.exe and UnlockerDriver5.sys in the same folder as EjectUSB. Unlocker requires admin privileges and doesn't work on Win9x.
- Improvement: Added a FAQ section to the documentation.
- Change: Slight change to the EjectUSB logo.
- Change: Separated the source code into its own ZIP file. Source code for EjectUSB will always be released with each version of EjectUSB.

Version 1.0 (1695 downloads)
- Initial release.

[ 07 August, 2009 ] • [ William Hedrick ] • [Bookmark and Share]

Comments (151)

[ Page 4 of 8 ] • [ << | < | 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 | > | >> ]

Hi everyone,

sorry but what is exactly a "hydrid" batch file ?

anyway great app !!!
[ 30 October, 2008 ] • [ BillyBoy ] • [ 04:08:23 ]

well, turns out i don't need the hybrid batch file at all. i have ejectusb.exe and the ini file on both the usb drive and truecrypt volume and i created a .bat file to be run by geek.menu upon clicking the eject button. one thing to note is that the .bat file accepts the host drive letter as the first parameter, and the truecrypt drive letter as the second, the reverse of geek.menu's default, which you can change yourself. i haven't tested it yet, but the .bat file should allow ejecting even if you checked the option to not mount the encrypted volume on the password prompt. the contents of the .bat file is below for geek.menu users who are interested. you could also probably use it for other usb menu software after some or no modifications. enjoy.

contents of eject.bat:
@echo off
if "%1"=="" goto xit
if "%2"=="" goto ejecthost
%2:\EjectUSB.exe
%1:\TrueCrypt\TrueCrypt.exe /d%2 /q /w /s /f
if errorlevel 1 goto xit
:ejecthost
%1:\EjectUSB.exe
:xit
[ 03 November, 2008 ] • [ jaybz ] • [ 21:30:14 ]

sorry, forgot to note that the ejectusb.ini i used on the truecrypt volume has DoNotEject=1
[ 03 November, 2008 ] • [ jaybz ] • [ 21:31:13 ]

desbloqueo de un pen drive
[ 12 November, 2008 ] • [ alejandro ] • [ 15:42:00 ]

Hi,

I have a suggestion for feature :
The possibility to have an other ejectUSB.ini, that we can launch in parameter.
Example : EjectUSB.exe "ejectUSBbis.ini"

It's because i use eject usb for two principal reasons without the same option ...

Thanks
[ 20 November, 2008 ] • [ Totoche ] • [ 07:56:02 ]

Thank you for this great little application. It took me a couple tries then I read the 'read me' and understood that the application needed to be on the device being removed. Makes sense. I put it on each of my removable devices and now I save a lot of time and frustration. Great Job!
[ 27 November, 2008 ] • [ Didier de Gery ] • [ 19:39:45 ]

An excellent program, works at school, but at home avast hates it.
[ 16 December, 2008 ] • [ Some dude ] • [ 16:30:39 ]

Hello,

Cool ! The new 1.4 is faster.

The only little problem stay to close firefox (portable) ... He think it's a crash at the next start!...

Thank you
[ 16 December, 2008 ] • [ Totoche ] • [ 16:58:50 ]

Thanks for your excelent tool, which saves me a lot of time.
Question: when do you expect Truecrypt support?
And it would be nice if you had some forums :D
[ 17 December, 2008 ] • [ mnt_schred ] • [ 18:28:51 ]

Sorry, didn't see the .bat script. You have made a relative path to truecrypt?
[ 17 December, 2008 ] • [ Thijs ] • [ 18:38:31 ]

Thanks William, EjectUSB 1.4 is VERY fast.

Merry X-mas!
[ 20 December, 2008 ] • [ Ricky999 ] • [ 15:18:28 ]

Unlocker found no handles. Searching Mark Russinovich's SysInternals ProcessExplorer for and handles to my WD Passport yielded nothing. And yet your nifty little program managed to eject my USB drive. I have no tasks or processes that were working with my USB drive. And yet, Windows won't gracefully eject my drive for some reason (it says that some program is still accessing it). My TaskList is clean, no malware, no hidden stuff, no rootkits, nothing! Now, how did your program manage to do it?

I have my WD Passport formatted in NTFS (512 bytes sized clusters, am a space freak) but it used to eject gracefully without qualms in the past. Recently, I've noticed that the hard-to-eject anomaly is happening too frequently for comfort. Should I suspect NTFS at (foul) play?

I am somewhat freaking amazed here. How the f did your little program do it? I've read all your blahs in the read me but I found no (ZERO) references left to my drive according to my own investigation! What's the secret?
[ 20 December, 2008 ] • [ Loloy D ] • [ 18:20:57 ]

I see that you have this open-sourced. I'll take a look at the code and see how you were able to pull this off. I suspect that my problem still remains with System Volume Information (or SVI) - a folder on the root of NTFS drives or partitions.

You said that your program doesn't do anything "unsafe" and that it only works with Windows APIs. That's actually really very comforting - add to that where you made this thing open source. And you have a clean way out disclaimer too, and you made this app with noble intentions, so I believe you got everything covered. I said this because I don't quite appreciate some of the comments above in this blog which say "this program doesn't work" or "this screwed my drive", etc.

By the way, I think it is worth mentioning that the way I was able to eject my USB drive was by using the aggressive mode "/eject" argument. I was not able to eject my WD Passport without it. From what I understand of your ReadMe, this argument "ignores configuration file settings and attempts to eject the specified drive; this bypasses all other functions (program closing, registry cleanup, etc.)." This leads me to conclude that there could be some Windows system process refusing to let go of my USB drive - again, probably has something to do with SVI. What bugs me is that I am not able to find any references to it from SysInternals ProcessExplorer. You should highlight that "/eject" argument for those difficult cases.

By the way, I failed to mention THANK YOU. Your work has indeed provided meaningful, sensible, usable and reliable functionality to me, not to mention saving from me a small server downtime and from lots of wasted time trying out stuff and experimenting to nowhere. Hmmm... come to think of it, I've also spent a lot of time too from reading this blog entry hehehe - but it has had its fruitful uses :D.
[ 21 December, 2008 ] • [ Loloy D ] • [ 17:34:39 ]

Hello,

I'm using Windows Vista and this app works great only I don't get a message balloon on successful ejection.
Is this a bug?

It did removed the USB disk.....
[ 31 December, 2008 ] • [ Grolo ] • [ 06:29:48 ]

@Loloy D, thanks for the kind words and I'm glad EjectUSB's been useful for you. Technically, /eject is LESS aggressive than running EjectUSB with default settings; all it does is run the ejection routine (which loops continuously until it succeeds). Using /eject, you miss out on the file cache flush (useful for external hard drives especially, though only works if you have admin privileges) and the various cleanup routines. Obviously if that works while default EjectUSB settings don't, stick with what works.

NTFS is a journaling file system, meaning there is a lot of behind-the-scenes note-taking (and therefore disk writes) that occur in addition to basic file operations; it provides a layer of safety against file corruption and loss, and theorhetically makes recovery from some critical errors trivial, but it also means the disk may be in use by the system even though you're not directly using files anymore. Regardless of the downsides, it's a good choice of file system for any hard drive due to reliability and error recovery (though you should not use it on a flash drive).

@Grolo, yes, the lack of an ejection success message balloon is a bug that I'm currently working to track down; it doesn't occur on any of the computers I have available (ranging from Win98SE to Vista SP1), so I've asked some beta testers to try and get me more information on the issue. My first guess is it's a unicode or non-English language issue. Version 1.5 is in the works though and I hope to get that issue resolved before release.
[ 11 January, 2009 ] • [ William Hedrick ] • [ 22:04:43 ]

Hello,
Avast detect a virus on EjectUSB ... can we fix it?
[ 13 January, 2009 ] • [ marciton ] • [ 15:06:24 ]

@marciton, make sure you have version 1.4; it's not setting off Avast (at least any version of Avast I've tried). Version 1.3 was the version primarily detected (falsely) by Avast.
[ 13 January, 2009 ] • [ William Hedrick ] • [ 15:48:42 ]

bonjour a tous
quand à l'utilitaire ejsct fflash USB il est très éfficasse,point de sécurité
pour l'usb storage et aussi pour la rapidité de son ejection.
trés bon travail qui mérite un grand encouragement et je vous souhete une
très bonne reussite à l'avenir,jje vous remerci,au revoir.
[ 14 January, 2009 ] • [ ramdaneastro ] • [ 09:01:36 ]

--------------------------
My first guess is it's a unicode or non-English language issue.
--------------------------

@William
I have a dutch windows vista so I think it's a good guess
[ 14 January, 2009 ] • [ Grolo ] • [ 14:29:11 ]

The program works for me, in that it closes programs and ejects the drive, but after a few seconds, I get an AutoIt error every time. It reads:

Line -1:

Error: The requested action with this object has failed.

I have not changed the configuration files that come with the program.
[ 19 January, 2009 ] • [ Andrew ] • [ 10:13:09 ]

[ Page 4 of 8 ] • [ << | < | 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 | > | >> ]

Add Comment