Page 3 of 4

Posted: 19 Apr 2016, 01:17
by Best-Code-in-Use
@rhinox202

Have you test this=
lexikos wrote:

Code: Select all

SetWorkingDir % A_WinDir
Eject(A_ScriptDir)

Eject() - For USB Mass Storage devices

Posted: 19 Apr 2016, 01:34
by Best-Code-in-Use
@SKAN

Hello,

thank you for sharing this script.
I have one Question:
Is the Performance for USB Drives not much better, if previously not the type of a Drive to be determined?

Code: Select all

DriveGet, VAR, Type, % DRV := SubStr( DRV, 1, 1 ) ":"
  If ( VAR = "" )
     Return  ( ErrorLevel := -1 ) + 1
 
  If ( VAR = "CDROM" ) {
     Drive, Eject, %DRV%  
     If ( nTC + 1000 > A_Tickcount ) 
        Drive, Eject, %DRV%, 1
     Return  ( ErrorLevel ? 0 : 1 )

Re: Eject() - For CD/DVD and USB Mass Storage devices

Posted: 19 Apr 2016, 18:26
by rhinox202
Thanks but I am already using the SetWorkingDir line, courtesy of an earlier post. Is it safe to assume that you aren't seeing this issue? I'll have to try compiling a simple script.

Re: Eject() - For CD/DVD and USB Mass Storage devices

Posted: 20 Apr 2016, 00:37
by Best-Code-in-Use
Yes, i have read that your Script is working,
when it is not compiled...
But lexikos post is not part of the Original Script.
:D

A really better control for the exe file is possible with this Script:
https://autohotkey.com/boards/viewtopic.php?f=6&t=16061

I'm not a Programmer, but this can be helpful...

Re: Eject() - For CD/DVD and USB Mass Storage devices

Posted: 26 Apr 2016, 13:59
by rhinox202
Thanks anyway for the help. I was trying to allow a compiled EXE to run from a flash drive and also eject said drive, but I can't get it working. Instead, I've resorted to running the EXE on the Desktop and having it eject the drive. After a little more thought, this seems to be the best option. Thanks again.

Re: Eject() - For CD/DVD and USB Mass Storage devices

Posted: 21 Sep 2017, 10:05
by Foolishguy
Hey SKAN or whomever this may concern.
I am having problems using this script to eject my External Hard-drive..
What I've done is replace DRV with X (the name of my EHDD) and it did not work..
I would like to know how this works please..

Re: Eject() - For CD/DVD and USB Mass Storage devices

Posted: 21 Sep 2017, 12:17
by SKAN
What I've done is replace DRV with X (the name of my EHDD) and it did not work..
I would like to know how this works please..
Try this:

Code: Select all

Eject( "X:" ) 
MsgBox %A_LastError%
What does the MsgBox show?

Re: Eject() : For Removable storage devices (Updated: 03-Oct-2019)

Posted: 03 Oct 2019, 08:34
by SKAN
New version : 03-Oct-2019, Check the first post.
Function re-written to be aware of UAS drives (USB Attached SCSI)

Re: Eject() : For Removable storage devices (Updated: 03-Oct-2019)

Posted: 03 Oct 2019, 13:51
by joedf
Cool! Didn't know UAS would affect it, thanks :+1:

Re: Eject() : For Removable storage devices (Updated: 03-Oct-2019)

Posted: 06 Oct 2019, 08:15
by carno
Thanks, I have been using this script EVERYDAY. :)

Re: Eject() : For Removable storage devices (Updated: 03-Oct-2019)

Posted: 14 Nov 2019, 06:26
by neogna2
SKAN, is this function the same as what is done by following Microsoft's procedure to safely remove hardware in Windows 10?
Look for the Safely Remove Hardware icon on the taskbar. If you don't see it, select Show hidden icons . Press and hold (or right-click) the icon and select the hardware you want to remove.
Cited from https://support.microsoft.com/en-us/help/4051300/windows-10-safely-remove-hardware

If yes then great, but then also consider updating the first post to make that more clear. It is the "safely remove hardware" phrase that is missing from the first post. Adding it may boost the google findability of your Eject() function for those searching for that phrase and AutoHotkey.

Re: Eject() : For Removable storage devices (Updated: 03-Oct-2019)

Posted: 04 Jan 2020, 00:56
by GaXve
Thank you for this Script!!!

On one particular device, the script does not seem to work for some reason. This is the notification I get:
  • "Eject Drive
    PNP_VetoDriver
    The driver supports the specified
    operation, but the driver rejected the
    operation."
Running the MsgBox Script, I get:
  • "Removable Media"
For reference, the USB device is this one:
https://www.monoprice.com/product?p_id=13506


Side note: This script works with another type of micro SD card reader, and every other USB device that I have.


Cheers!

Re: Eject() : For Removable storage devices (Updated: 03-Oct-2019)

Posted: 04 Jan 2020, 02:36
by SKAN
GaXve wrote:
04 Jan 2020, 00:56
The driver supports the specified operation, but the driver rejected the operation.
Just to confirm: You are able to eject it from Tray icon?

If yes, can you please post a screen shot of "Safely Remove Hardware" menu?

Re: Eject() : For Removable storage devices (Updated: 03-Oct-2019)

Posted: 04 Jan 2020, 05:47
by GaXve
I am able to eject from Tray Icon

Re: Eject() : For Removable storage devices (Updated: 03-Oct-2019)

Posted: 02 Mar 2020, 00:48
by GaXve
To eject this specific USB Card Key, you must select the "bottom" description vs the "top" description. I don't know enough about drivers, but perhaps this accounts for something.

Re: Eject() : For Removable storage devices (Updated: 03-Oct-2019)

Posted: 06 Mar 2020, 03:43
by haichen
Is it possible to restart an ejected drive? With power on and eject I would like to turn a hard disk on and off for a backup. As a small protection against encryption trojans. I already tried it with the RestartSrDev tool from Uwe Sieber (https://www.uwe-sieber.de/english.html known for his great USB Drive Letter Manager), but without success.

Re: Eject() : For Removable storage devices (Updated: 03-Oct-2019)

Posted: 17 Mar 2020, 05:38
by SKAN
haichen wrote:
06 Mar 2020, 03:43
Is it possible to restart an ejected drive?
I have tried in vain, several years ago. Will try again and shall post if I find anything useful.

Meanwhile, I believe this is best done with external hardware support.
* Don't try this.* . Just a theory!!


Spoiler

Re: Eject() : For Removable storage devices (Updated: 03-Oct-2019)

Posted: 17 Mar 2020, 08:16
by haichen
I was able to reboot my USB hard drive after it was ejected. If it was ejected with "Problem=47" the corresponding USB hub must be started.
For this you need the hardware ID of the hub.

Code: Select all

hdid= USB\VID_174C&PID_55AA\35600000000000001A9B ;example
hdid=*35600000000000001A9B*   ; you can use *
run, %A_ScriptDir%\RestartSrDev.exe %hdid% -f -na -d
You can get the ID from the UsbDriveInfo Tool from Uwe Sieber


I found another method to get the ID:

Code: Select all

for k, hdId in getHardwareID47()
   run, %A_ScriptDir%\RestartSrDev.exe %hdid% -f -na -d
return

getHardwareID47(){
    hwid := []
    for objItem in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_USBHub where ConfigManagerErrorCode=47"){
        hwid.Push(objItem.deviceid)
    }
    return hwid
}
I forget: The script has to run as admin!
Thanks

Re: Eject() : For Removable storage devices (Updated: 03-Oct-2019)

Posted: 23 Mar 2020, 22:42
by SKAN
haichen wrote:
17 Mar 2020, 08:16
I was able to reboot my USB hard drive after it was ejected.

Thanks :)
Does RestartSrDev work in Windows 7 ?

Re: Eject() : For Removable storage devices (Updated: 03-Oct-2019)

Posted: 24 Mar 2020, 03:53
by haichen