Eject() : For Removable storage devices

Post your working scripts, libraries and tools
Best-Code-in-Use
Posts: 147
Joined: 01 Dec 2015, 05:13
Location: Germany

19 Apr 2016, 01:17

@rhinox202

Have you test this=
lexikos wrote:

Code: Select all

SetWorkingDir % A_WinDir
Eject(A_ScriptDir)
Greetings Best-Code-in-Use
Best-Code-in-Use
Posts: 147
Joined: 01 Dec 2015, 05:13
Location: Germany

Eject() - For USB Mass Storage devices

19 Apr 2016, 01:34

@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 )
Greetings Best-Code-in-Use
rhinox202
Posts: 10
Joined: 30 Sep 2015, 10:22

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

19 Apr 2016, 18:26

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.
Best-Code-in-Use
Posts: 147
Joined: 01 Dec 2015, 05:13
Location: Germany

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

20 Apr 2016, 00:37

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...
Greetings Best-Code-in-Use
rhinox202
Posts: 10
Joined: 30 Sep 2015, 10:22

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

26 Apr 2016, 13:59

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.
Foolishguy
Posts: 21
Joined: 09 Sep 2017, 03:30

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

21 Sep 2017, 10:05

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..
User avatar
SKAN
Posts: 757
Joined: 29 Sep 2013, 16:58

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

21 Sep 2017, 12:17

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?
User avatar
SKAN
Posts: 757
Joined: 29 Sep 2013, 16:58

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

03 Oct 2019, 08:34

New version : 03-Oct-2019, Check the first post.
Function re-written to be aware of UAS drives (USB Attached SCSI)
User avatar
joedf
Posts: 7734
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

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

03 Oct 2019, 13:51

Cool! Didn't know UAS would affect it, thanks :+1:
carno
Posts: 212
Joined: 20 Jun 2014, 16:48

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

06 Oct 2019, 08:15

Thanks, I have been using this script EVERYDAY. :)
neogna2
Posts: 74
Joined: 15 Sep 2016, 15:44

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

14 Nov 2019, 06:26

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.
User avatar
GaXve
Posts: 89
Joined: 30 Mar 2019, 18:20

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

04 Jan 2020, 00:56

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!
User avatar
SKAN
Posts: 757
Joined: 29 Sep 2013, 16:58

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

04 Jan 2020, 02:36

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?
User avatar
GaXve
Posts: 89
Joined: 30 Mar 2019, 18:20

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

04 Jan 2020, 05:47

I am able to eject from Tray Icon
Attachments
2020_01_04_05_43_53_.png
2020_01_04_05_43_53_.png (37.18 KiB) Viewed 2223 times
User avatar
GaXve
Posts: 89
Joined: 30 Mar 2019, 18:20

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

02 Mar 2020, 00:48

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.
Attachments
Eject USB micro SD Card Key vs External Hard Drive.png
Eject USB micro SD Card Key vs External Hard Drive.png (5.08 KiB) Viewed 1831 times
User avatar
haichen
Posts: 502
Joined: 09 Feb 2014, 08:24

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

06 Mar 2020, 03:43

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.
User avatar
SKAN
Posts: 757
Joined: 29 Sep 2013, 16:58

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

17 Mar 2020, 05:38

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
User avatar
haichen
Posts: 502
Joined: 09 Feb 2014, 08:24

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

17 Mar 2020, 08:16

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
User avatar
SKAN
Posts: 757
Joined: 29 Sep 2013, 16:58

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

23 Mar 2020, 22:42

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 ?

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 18 guests