Jump to content

[Question] Right click on Removable USB Flash drive and Eject


MrChris

Recommended Posts

I have a 2GB USB Sandisk Cruzer Micro and when I plug it in and go into My Computer and Right Click on the drive I have an option to Eject. My question is What function does it call? I am trying to utilize the same function call (if that is what it is) in a batch script or AutoIt script that way I don't need to use any third part apps or EXEs to eject the media.

Thanks,

MrChris

Title edited -- Please, use [TAGS] in your topic's title.

--Sonic

Link to comment
Share on other sites


If you are sure your data is copied/saved/moved completely, you can unplug directly your key without any problem (wait 5s after copy operation for example). The eject function scan handles on the usb key and if are present it says close all programs, if empty it just says you can remove your key (and disconnect from device manager to disable the key).

When the usb key is new, we try to use Eject function but after many uses you unplug & replug directly ...I do that with mine and I havn't any corrupt data.

Link to comment
Share on other sites

  • 4 weeks later...

So can one call such a function from a batch script or autoit script without using any third party programs or exe's? I basicly want to be able to do the same eject from inside my script that windows does when you right click on the drive from explorer.

Thanks again.

MrChris

Link to comment
Share on other sites

Just ensure that no disk activity is occurring, then simply unplug it. You don't need to use that function, unless your USB drive is formatted with NTFS (which is *highly* unrecommended, as NTFS journalling filesystem will wear out flash RAM very quickly).

Link to comment
Share on other sites

The only main reason I use NTFS on my 2GB Cruzer mini is so I can use the compress attrib. If I was to convert it to FAT or FAT32 is there any way I can compress the data on the disk without using any type of ZIP or RAR compression?

MrChris

Link to comment
Share on other sites

You should be able to umount volume with diskpart or mountvol which the first step to avoid data loss.

Then using perhaps devcon (i'm not sure it can) disable the device. I'm not sure the second step is essential.

Link to comment
Share on other sites

The only main reason I use NTFS on my 2GB Cruzer mini is so I can use the compress attrib. If I was to convert it to FAT or FAT32 is there any way I can compress the data on the disk without using any type of ZIP or RAR compression?

MrChris

NTFS is not recommended for use on drives that use Flash memory, as the number of writes it does is far higher than a standard FAT filesystem. It'll work, but don't expect it to last long.
Link to comment
Share on other sites

the one and only factor that determines if you can safely remove a drive without 'ejecting' it first is whether or not windows has 'write-behind caching' enabled for that device.

luckily i -think- windows disables it by default for removable drives, though i could be wrong.

Edited by i'm not ophiel
Link to comment
Share on other sites

Actually, to be on the safe side, best thing is to use Unmount by Christoph H. Hochstaetter, yes it was written in 1995 for NT4, but it still works on 2K and XP :thumbup .

Here:

http://www.uwe-sieber.de/usbstick_e.html

http://www.uwe-sieber.de/files/unmnt10.zip

From the docs:

I have written these Utilities to allow safe removal of removable media, such as magneto-optical disk, bernoulli disks, a Syquest disk or similar devices. When you have NTFS on a removable disk, you are not allowed to simply remove the media, when there are still open files. In case of FAT, Windows NT allows the removal of the media, but it is not recommended to do so, if there are still open files. HPFS is even more sensitive to media removal, so Windows NT does not allow formatting removable disks with HPFS, neither does OS/2.

Because UNMOUNT.EXE uses MNT.EXE as a DLL, it is required to have MNT.EXE in the same directory as UNMOUNT.EXE. Otherwise UNMOUNT.EXE does not work.

One common method of removing disks with NTFS filesystem is to run CHKDSK /F on the drive and afterwards removal is allowed by pressing the eject button, but this is quite time consuming.

UNMOUNT is a utility, which helps is this case. You simply type UNMOUNT <drive>: to eject the media. This works on all removable media (even on CD-ROMs). UNMOUNT tries to lock the drive for exclusive use. If this is successful, UNMOUNT will dismount the drive and then eject the media. If there are still open files on the disk or another process (e.g. FORMAT) has locked the drive exclusively, locking fails and the program will exit.

You can specifiy UNMOUNT -l <drive>: This will retry locking the drive continously, until you press CTRL-C or CTRL-BREAK. In the meantime you can close programs, which are currently accessing the drive, e.g. the File Manager or go to the Command Prompt and switch to another driver, e.g. by typing C: on the command line.

You can also try UNMOUNT -a -l <drive>: This will delete the drive letter definition after locking the drive. This is useful, when you want to ensure, that no process can access the drive after it has been removed and prevents error dialogs like "There is no disk in the drive (A)bort, ®etry, (I)gnore". You need MNT to redefine the drive letter again (described later).

You can also delete the drive letter before you attempt to lock the drive. This is useful, if there are processes, that want to open files on your removable drive, while you are going to lock and eject your media. To do so type UNMOUNT -b -a -l <drive:> or simply UNMOUNT -bal <drive:>. After you typed that, the drive letter definition is removed immediately, but processes, that already had open files can still use these files and close them correctly.

To see other options, type UNMOUNT -?

Or, better still, one of the two proggies written by Uwe Sieber, same address:

http://www.uwe-sieber.de/usbstick_e.html

http://www.uwe-sieber.de/files/removedrive.zip

http://www.uwe-sieber.de/files/ejectmedia.zip

Also, you can use devcon:

http://support.microsoft.com/?kbid=311272

devcon remove @usb\*

Will remove ALL USB devices :w00t:

Finally, check this:

http://portableapps.com/node/639

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...