Page 2 of 4
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 13 Sep 2014, 05:03
by jantom
DeviceType: 7
DeviceNumber: 2
PartitionNumber: 1
---------------------------
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 13 Sep 2014, 05:58
by SKAN
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
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 13 Sep 2014, 12:40
by jantom
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
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 13 Sep 2014, 12:58
by SKAN
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?
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 13 Sep 2014, 15:05
by jantom
Standalone. I just trigger the function with: Eject ( "F:" ).
Many thanks for looking into it.
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 14 Sep 2014, 09:19
by SKAN
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
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 14 Sep 2014, 10:11
by jantom
Great! It works fine with my drive now, too.
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 14 Sep 2014, 22:49
by lexikos
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,
Code: Select all
SetWorkingDir % A_WinDir
Eject(A_ScriptDir)
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 15 Sep 2014, 00:19
by joedf
Good catch
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 15 Sep 2014, 11:16
by SKAN
lexikos wrote:Code: Select all
SetWorkingDir % A_WinDir
Eject(A_ScriptDir)
I have never tried anything like this before.
Thanks.
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 17 Sep 2014, 22:54
by lexikos
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.
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 18 Sep 2014, 23:20
by SKAN
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.
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 07 Dec 2014, 06:58
by vangogh
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
^!u::
DriveGet, List, List, REMOVABLE
StringReplace, List, List, A
Drv := SubStr( List,1,1 ) . ":"
Eject(Drv)
Return
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 07 Dec 2014, 23:40
by SKAN
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".
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 08 Dec 2014, 03:55
by ozzii
or before the solution of SKAN do:
DriveGet, Drv, Type, %Drv%
So you can have the Type of the drive
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 24 May 2015, 12:50
by j-t-r
Thanks! Integrated it to my special AHK-Totalcmd interface
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 26 Jun 2015, 05:02
by jhondoeme
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
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 09 Sep 2015, 10:56
by bichlepa
Thanks, SKAN!
I have included the Eject() function into
AutoHotFlow. There is now an action
Eject drive.
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 06 Oct 2015, 04:56
by Kamal Awasthi
Good work!
Probably you should add one Tray Tip indicating the successful ejection of a drive.
Re: Eject() - For CD/DVD and USB Mass Storage devices
Posted: 17 Apr 2016, 17:10
by rhinox202
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!