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?
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.
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..
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
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.
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 Cr8zy_Ivan
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."
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 Cr8zy_Ivan
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 Cr8zy_Ivan
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)
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
External HDD is usually connected via a USB 3.0 cable.
If you find the red wire (VBus) cut it and and wire it to a mechanical on/off switch...
then one may off and on the switch to re-power the HDD.
This should be as good as unplugging and plugging back the HDD, I believe.
Now, if we replace the mechanical switch with a USB relay, then we can turn off/on the HDD with
a software command either through the CLI or DLL provided with the USB relay.
CommandApp_USBRelay.exe afEd5 close 01 ; Power off
CommandApp_USBRelay.exe afEd5.exe open 01 ; Power on
afEd5 is the serial number of hardware, which can be ascertained with the tool provided along with the DLL and CLI utility
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.
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
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)