Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

umount USB stick (deveject) [CMD]


  • Please log in to reply
14 replies to this topic
leonix
  • Members
  • 2 posts
  • Last active: Jan 28 2005 04:00 PM
  • Joined: 28 Jan 2005
deveject unmounts ("eject") your usb mass-storage device

ftp://ftp.heise.de/pub/ct/listings/0316-208.zip

It is a win32 console application and includes the source-code.
I would be happy if it can be included into autohotkey as command.
(to omit the ugly black cmd-window).

Leo.

BoBo
  • Guests
  • Last active:
  • Joined: --
@ leonix
Junge, Junge, (boy oh boy)
you're in BIG trouble now :twisted:

1) if its a recommandation it would belong to the Forums Utilities Section
2) if you request to implement it within AHK it belongs to the Forums Wish Section
3) if you agree on both of the above, will prevent you from going directly to Jail

@ Chris
have I requested a Jail Section so far ? :lol:

BoBo
  • Guests
  • Last active:
  • Joined: --

(to omit the ugly black cmd-window).

@ leonix
Check this out:

RunWait, %COMSPEC% /C ECHO Es lebe die DOS Box > leo.txt,, Hide
MsgBox, 0, Greetings from an ugly DOS box, Yes there was a ugly black cmd window!`nbut you havn't seen it!`nCause it was hidden.`nBye., 3
Run, notepad %A_WorkingDir%\leo.tx,, Max
WinWaitClose, leo.txt - Notepad
FileDelete, leo.txt


OK, now let's go back and RTFM :wink:

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

deveject unmounts ("eject") your usb mass-storage device

I would be happy if it can be included into autohotkey as command.
(to omit the ugly black cmd-window).

I will add it to the to-do list. Thanks.

I've moved this topic to the Utilities forum since others might find this tool useful.

BoBo
  • Guests
  • Last active:
  • Joined: --
@ leonix
Thx for sharing it. Looks quite usefull. :D

Babis
  • Members
  • 69 posts
  • Last active: Aug 26 2015 09:31 AM
  • Joined: 08 Dec 2005
I know that this is almost a year old, but as I was searching how to umount my USB flash disk, I found it, but it does not working. I am wondering if there is another way to do it.

not-logged-in-daonlyfreez
  • Guests
  • Last active:
  • Joined: --
More related stuff

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
A wrapper for DevEject.exe to Eject USB Drives:

Msgbox, % DevEject("J:")

DevEject( Drive="" ) { 
 IfNotExist, %Drive%\, Return 4
 IfNotExist, DevEject.exe, Return -1
 RunWait, DevEject.exe -EjectDrive:%Drive%,, Hide UseErrorLevel
 Err := ErrorLevel
 DriveGet, Status, Status, %Drive%
Return ( Status="Invalid" ) ? 0 : ( Err=0 ) ? 16 : Err
}

Returns an errorcode of 0 if the drive is ejected successfully.

There is a native way of ejecting drives ( also given in AHK Doc ) : Eject any drive by Thalon

One advantage of DevEject is that it powers down the device which is as good as working from "Safely Remove Hardware" icon available on Tray. This means the drive is no longer listed in explorer windows and other file/folder dialogs though the drive may still be left unplugged.

On a related note: To programmatically activate the "Safely Remove Hardware" dialog from a script, use:

Run, %A_WinDir%\System32\rundll32.exe shell32.dll`,Control_RunDLL hotplug.dll

Download:
DevEject.exe [ 45 KB ]
DevEject.cpp [ 25 KB ]

:)

  • Guests
  • Last active:
  • Joined: --
any ideas why deveject doesnt work with my Western Digital Passport 60gb ? i can eject my kingston usb stick just fine

gives me error:
10


?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

gives me error:
10
?


From CPP file I can see
deec_ErrorGettingDeviceId = 10

You may try using the Device ID directly to eject it.

:)

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
out of curiosity... why not just left click the icon in the system tray once (note: not right click or double click - left click once), choose the device you want to eject from the small menu that appears by left clicking once to stop and eject the device? It's a built-in feature that works quite well in most cases...

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
It is harder when you keep plugging in and out various USB devices.
BTW, I never knew of this single click. Thanks. I will use the tip for my laptop.

:)

  • Guests
  • Last active:
  • Joined: --
@Skan

i got the script that gives me the device serial but how do you mean i should use it with your wrapper?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

i got the script that gives me the device serial but how do you mean i should use it with your wrapper?


You have to use it directly with DevEject.exe !

The problem with DevEject.exe is that it returns 0 for
successful ejection as well when the device is in use. That is why the need to wrap it into a function.

So I test it like follows:

Run DevEject and capture its errorcode
Check the Drive Status to see whether it is still there
If drive is not there, fine, return 0
if not
{
if errorlevel is zero, not fine, return undefined errorlevel of 16
or else return deveject errorlevel itself
}

The above is what the last line does:

Return ( Status="Invalid" ) ? 0 : ( Err=0 ) ? 16 : Err

Hope you can adapt this to your needs.

  • Guests
  • Last active:
  • Joined: --
whats wrong with this code, i get nothing?

Driveletter might change so i want to use the serial

Msgbox, % DevEject(%kingston%:)

SetFormat, Integer, H
DriveGet, DrvList, List, REMOVABLE
Loop, Parse, DrvList
{   DriveGet, DrvSerial, Serial, %A_Loopfield%:
   StringTrimLeft, DrvSerial, DrvSerial,2
   StringUpper, DrvSerial, DrvSerial
   if( %DrvSerial% = 7CFK5E15 ){
   %A_Loopfield% := kingston
   }
}

DevEject( Drive="" ) {
 IfNotExist, %Drive%\, Return 4
 IfNotExist, DevEject.exe, Return -1
 RunWait, DevEject.exe -EjectDrive:%Drive%,, Hide UseErrorLevel
 Err := ErrorLevel
 DriveGet, Status, Status, %Drive%
Return ( Status="Invalid" ) ? 0 : ( Err=0 ) ? 16 : Err
}