Eject() : For Removable storage devices

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Cr8zy_Ivan
Posts: 131
Joined: 30 Mar 2019, 18:20

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

25 Mar 2020, 03:05

SKAN wrote:
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?
I found the problem ➔ Realtek USB 3.0 Card Reader ⮧
Device Manager\Universal Serial Bus controllers\Realtek USB 3.0 Card Reader ➔ Uninstall device (Check ✔: Delete the driver software for this device); Reboot.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

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

25 Mar 2020, 14:51

haichen wrote:
24 Mar 2020, 03:53
I suppose so. But I don't have Windows 7 anymore.
Your fine example works for me in Win 10 but not in Win 7.
Will it be useful if a global variable (or a ByRef parameter) is set to DeviceID when eject is called?
My Scripts and Functions: V1  V2
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

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

25 Mar 2020, 14:52

GaXve wrote:
25 Mar 2020, 03:05
I found the problem ➔ Realtek USB 3.0 Card Reader ⮧
Device Manager\Universal Serial Bus controllers\Realtek USB 3.0 Card Reader ➔ Uninstall device (Check ✔: Delete the driver software for this device); Reboot.
Thank you very much for the feedback. I highly appreciate it, :thumbup:
User avatar
Cr8zy_Ivan
Posts: 131
Joined: 30 Mar 2019, 18:20

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

25 Mar 2020, 16:59

SKAN wrote:
25 Mar 2020, 14:52
GaXve wrote:
25 Mar 2020, 03:05
I found the problem ➔ Realtek USB 3.0 Card Reader ⮧
Device Manager\Universal Serial Bus controllers\Realtek USB 3.0 Card Reader ➔ Uninstall device (Check ✔: Delete the driver software for this device); Reboot.
Thank you very much for the feedback. I highly appreciate it, :thumbup:
You bet. Thank You for your script! :)
User avatar
Cr8zy_Ivan
Posts: 131
Joined: 30 Mar 2019, 18:20

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

06 Apr 2020, 18:42

Now the only trouble is this driver auto-installs itself every time. And I have still to figure out how to prevent a driver from auto-installing itself. If anyone has any tips, please let me know
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

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

06 Apr 2020, 19:19

GaXve wrote:
06 Apr 2020, 18:42
Now the only trouble is this driver auto-installs itself every time. And I have still to figure out how to prevent a driver from auto-installing itself. If anyone has any tips, please let me know
I'm not sure. I googled and this seems useful.
https://www.ghacks.net/2017/06/03/stop-windows-from-installing-drivers-for-specific-devices/
User avatar
Cr8zy_Ivan
Posts: 131
Joined: 30 Mar 2019, 18:20

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

08 Apr 2020, 02:46

Hey Skan thanks for the share! After going through the procedure though, I found it tedious solution to implement. Because I have Windows home, I had to first install "group policy editor" (https://www.itechtics.com/enable-gpedit-windows-10-home/), and also find a replacement driver (which I did not manage to find). My impatience got the best of me :( . I found an alternative though, "show or hide updates" troubleshooter tool. If this can help anyone who might be looking, here's the link!

https://www.repairwin.com/prevent-a-specific-windows-update-or-driver-from-installing-in-windows-10/

Cheers!
Technomage Awunes
Posts: 9
Joined: 25 Oct 2021, 20:33

Re: Eject() : For Removable storage devices

15 Aug 2022, 04:16

I'm attempting to eject a drive but it only seems to work when the script is not compiled.

here's the result of the message box you would like for the test... Note I modified it a little to show both the drive letter and the "MediaType".
MsgBox % Clipboard := "drive letter " A_ScriptDir " is " Eject(A_ScriptDir,,True).MediaType

Code: Select all

---------------------------
---------------------------
SetTime(ctrl+t).exe
---------------------------
drive letter F: is Removable Media
---------------------------
OK   
---------------------------
And a second message showing what drive letter it's checking

Here's the compiled script's "Lines most recently executed" after attempting to eject using simply Eject(A_ScriptDir)

Code: Select all

131: Eject(A_ScriptDir)  
007: IOCTL_STORAGE_GET_DEVICE_NUMBER := 0x2D1080
008: OPEN_EXISTING := 3
008: hVol := 0
008: sPHDRV := ""
008: qStr := ""
008: qEnum := ""
008: nDID := 0
008: nVT := 1
009: AMT := "[Removable Media][External hard disk media]"
009: dObj := {}
010: hVol := DllCall("CreateFile", "Str","\\.\" . (DRV:=SubStr(DRV,1,1) . ":"), "UInt",0,"UInt",0, "Ptr",0,"UInt",OPEN_EXISTING, "UInt",0, "Ptr",0, "Ptr")
012: if (hVol = -1 )  
017: VarSetcapacity(STORAGE_DEVICE_NUMBER,12,0)  
018: DllCall("DeviceIoControl", "Ptr",hVol, "UInt",IOCTL_STORAGE_GET_DEVICE_NUMBER,"Int",0, "Int",0, "Ptr",&STORAGE_DEVICE_NUMBER, "Int",12, "PtrP",0, "Ptr",0)  
020: DllCall( "CloseHandle", "Ptr",hVol )  
021: sPHDRV := "\\\\.\\PHYSICALDRIVE" . NumGet(STORAGE_DEVICE_NUMBER,4,"UInt")
022: qStr := "Select * from Win32_DiskDrive where DeviceID='$$$'"
023: qEnum := ComObjGet("winmgmts:").ExecQuery(StrReplace(qStr,"$$$",sPHDRV))._NewEnum() (0.05)
024: qEnum[dObj]   (0.13)
025: if ( DontEject )  
030: if ! ( DontCheck || InStr(AMT, "[" . dObj.MediaType . "]", True) )  
036: if ! ( DllCall("GetModuleHandle", "Str","SetupAPI.dll", "Ptr") )  
038: DllCall("LoadLibrary", "Str","SetupAPI.dll", "Ptr")  
039: }
040: DllCall("SetupAPI\CM_Locate_DevNode", "PtrP",nDID, "Str",dObj.PNPDeviceID, "Int",0)  
041: DllCall("SetupAPI\CM_Get_Parent", "PtrP",nDID, "UInt",nDID, "Int",0)  
042: VarSetCapacity(VAR,520,0)  
043: DllCall("SetupAPI\CM_Request_Device_Eject","UInt",nDID, "PtrP",nVT,"Str",VAR, "Int",260, "Int",0)   (0.09)
045: ErrorLevel := ( nVT=0 ? 0 : ["PNP_VetoTypeUnknown
The specified operation was reje" . "cted for an unknown reason.","PNP_VetoLegacyDevice
The device does not support " . "the specified PnP ope
061: Return,dObj
I see there is an error returned but not sure what to do about it.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Google [Bot] and 158 guests