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

Post your working scripts, libraries and tools
jantom
Posts: 12
Joined: 21 Feb 2014, 10:49

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

13 Sep 2014, 05:03

DeviceType: 7
DeviceNumber: 2
PartitionNumber: 1
---------------------------
User avatar
SKAN
Posts: 310
Joined: 29 Sep 2013, 16:58

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

13 Sep 2014, 05:58

jantom wrote:DeviceType: 7
DeviceNumber: 2
PartitionNumber: 1
---------------------------


jantom, if DeviceType is 7 then sPHDRV will not be blank. Did you insert MsgBox correctly?

you wrote:hVol = 248
sPHDRV = (blank)
ErrorLevel = -2
jantom
Posts: 12
Joined: 21 Feb 2014, 10:49

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

13 Sep 2014, 12:40

But yes, it is blank.
It looks like the following condition is not met:

If ( NumGet( STORAGE_DEVICE_NUMBER, "UInt" ) = FILE_DEVICE_DISK )




If I omit the above if clause then sPHDRV = \\\\.\\PHYSICALDRIVE0
User avatar
SKAN
Posts: 310
Joined: 29 Sep 2013, 16:58

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

13 Sep 2014, 12:58

hi jantom, give me a day's time. I am about borrow a similar model. I will test and let you know. :)

It looks like the following condition is not met


Not possible, because FILE_DEVICE_DISK := 0x00000007 is initialized and our test revealed DeviceType: 7
Are you trying the function as standalone or running it as a part of an another script?
jantom
Posts: 12
Joined: 21 Feb 2014, 10:49

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

13 Sep 2014, 15:05

Standalone. I just trigger the function with: Eject ( "F:" ).
Many thanks for looking into it.
User avatar
SKAN
Posts: 310
Joined: 29 Sep 2013, 16:58

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

14 Sep 2014, 09:19

Hi jantom, I have tested Eject() function with following "FIXED" type USB drive and it works fine.

Caption: Seagate Backup+ BK USB Device
Description: Disk drive
DeviceID: \\.\PHYSICALDRIVE1
InterfaceType: USB
MediaLoaded: -1
MediaType: External hard disk media
Model: Seagate Backup+ BK USB Device
Name: \\.\PHYSICALDRIVE1
Partitions: 1
PNPDeviceID: USBSTOR\DISK&VEN_SEAGATE&PROD_BACKUP+_BK&REV_0836\NA53TNPC&0
SectorsPerTrack: 63
Status: OK
jantom
Posts: 12
Joined: 21 Feb 2014, 10:49

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

14 Sep 2014, 10:11

Great! It works fine with my drive now, too.
lexikos
Posts: 5453
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

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

14 Sep 2014, 22:49

Nice script. One trap with using this in a script on the drive itself is that any process with its working directory on the drive (such as the script itself) will prevent it from ejecting. In that case,
User avatar
joedf
Posts: 5996
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

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

15 Sep 2014, 00:19

Good catch
User avatar
SKAN
Posts: 310
Joined: 29 Sep 2013, 16:58

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

15 Sep 2014, 11:16



I have never tried anything like this before. :shock:
Thanks. :)
lexikos
Posts: 5453
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

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

17 Sep 2014, 22:54

You mean having a script eject the drive it's running off? I needed this for a script which copies tools onto a PC and then ejects, so I can use the drive elsewhere or run anti-malware scans without having my tools quarantined. ;)
User avatar
SKAN
Posts: 310
Joined: 29 Sep 2013, 16:58

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

18 Sep 2014, 23:20

lexikos wrote:You mean having a script eject the drive it's running off?


That - I have tried and succeeded.

Eject() is in my std lib folder. I have 5 Win versions on my computer ( XP, Win 7, Win 8.1, Win 7 x64 and Win 8.1 x64 ) and AutoHotkey is installed and shared on a common folder ( D:\AutoHotkey ).

I have now placed your two-liner script in my USB mass storage devices. Double clicking it from Windows Explorer ejects the drive and closes the explorer automatically in Win 7 & 8.1. However, in Win XP, Windows Explorer navigates to "Control Panel" after the drive is ejected, and so, requires an additional click to close the Explorer.

:)
vangogh
Posts: 3
Joined: 16 May 2014, 06:05

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

07 Dec 2014, 06:58

Hi there,

sorry for the newbie question - how do i get it to work with a hotkey?

i added this code after the eject.ahk but nothing happened:

Code: [Select all] [Download] GeSHi © Codebox Plus

^!u::

DriveGet, List, List, REMOVABLE

StringReplace, List, List, A

Drv := SubStr( List,1,1 ) . ":"

Eject(Drv)

Return
User avatar
SKAN
Posts: 310
Joined: 29 Sep 2013, 16:58

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

07 Dec 2014, 23:40

Insert MsgBox % Drv before Eject and see the drive letter it displays. Maybe you are trying to eject an external HDD, which is usually of type "FIXED".
ozzii
Posts: 291
Joined: 30 Oct 2013, 06:04

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

08 Dec 2014, 03:55

or before the solution of SKAN do:
DriveGet, Drv, Type, %Drv%
So you can have the Type of the drive
j-t-r

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

24 May 2015, 12:50

Thanks! Integrated it to my special AHK-Totalcmd interface ;-)
jhondoeme

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

26 Jun 2015, 05:02

Hi,

thanks for your software. Unfortunatelly I got an error. It is complaining about a "Member not found" on method _NewEnum() on line 029.
I am trying to remove a USB Stick on Windows 7 Enterprise SP1 x64.

Regards
JD
User avatar
bichlepa
Posts: 136
Joined: 15 Aug 2014, 06:44
GitHub: bichlepa
Contact:

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

09 Sep 2015, 10:56

Thanks, SKAN!
 
I have included the Eject() function into AutoHotFlow. There is now an action Eject drive.
Scripting is too complicated? Try AutoHotFlow, the graphical automation tool! Written in AutoHotkey.
Kamal Awasthi
Posts: 22
Joined: 19 Aug 2015, 04:35
Facebook: kamalawasthi97
GitHub: KamalAwasthi

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

06 Oct 2015, 04:56

Good work!
Probably you should add one Tray Tip indicating the successful ejection of a drive.
rhinox202
Posts: 8
Joined: 30 Sep 2015, 10:22

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

17 Apr 2016, 17:10

Hello. I'm trying to use the Eject function in my script, but I'm having a weird issue. The issue being that eject won't work when I compile the script. It works fine uncompiled. However, when the same script is compiled and run, the Eject function returns 1 for success, 0 for ErrorLevel, 0 for A_LastError, and the drive does not eject. Run it uncompiled and boom the device ejects. It's very odd.

My machine is running Windows 10 with AHK 1.1.23.05. The function has not been modified from its original state and "Eject(USBdrv)" is used to call it. USBdrv being "F", in this specific case. The script was originally compiled with the "Unicode 32-bit" bin, but I've also tried ANSI to no avail. Any thoughts? Thanks!

Return to “Scripts and Functions”

Who is online

Users browsing this forum: partof and 17 guests