EDIT 3: Much better version posted later on at https://portableapps.com/node/639#comment-2238
EDIT: Updated scripts, fully working with autorun and no dos boxes are in my reply below.
EDIT 2: This doesn't work from a limited account, but doesn't cause any problems, it just won't automatically unmount if you aren't an administrator.
I don't know if this has been discussed before, I'm kind of new here, but I found a nice little way to safely remove your USB drive, without navagating through the menus in windows XP. AFAIK this will only work on WinXP, not 95/98, though I haven't tested them.
Credits to http://ask-leo.com/is_there_a_way_to_safely_remove_hardware_from_a_batch... which is where I found part of this solution.
First, get devcon from http://support.microsoft.com/?kbid=311272 This is a command line device management program.
Extract it somewhere, and run:
devcon status *
This will list all the devices on your computer. What you are looking for is usually the USB Mass Storage Device. It should be whatever the TOP line is on the screen to safely remove hardware.
In my case I get this:
Name: USB Mass Storage Device
Driver is running.
Now see if you can remove it with this line:
devcon remove "USB\VID_0781&PID_7113"
(note the quotes around the device string, and the last section cut off. Not sure why but it only works without that part)
Now you need to make two little batch files:
copy devcon.exe %temp%
copy remove.bat %temp%
ping -n 5 127.0.0.1
%temp%\devcon remove "USB\VID_0781&PID_7113"
How this works:
You run startmenu.bat. PStart pops up. Once you close PStart, it copies devcon and the remove.bat files to the temp directory. It switches to the c: drive so that it isn't holding the flash drive open, uses ping to wait 5 seconds, then runs remove.bat
Remove.bat dismounts the flash drive, then delete's itself, leaving no traces on the system.
It seems that it won't unmount the drive if there are any files still open on it, which is a good thing IMHO. But if your programs crash or something it may not unmount automatically.
I'm now trying to figure out a way to make the dos window not show up. I'll post here if I figure that out.