I have tested it with CD- and USB-drives and worked.
I do not know it's limitations (e.g. OS), if you find some please post them...
You have simply to adjust the Driveletter.
Driveletter = I: DrivePath = \\.\%Driveletter% hVolume := DllCall("CreateFile" , str, DrivePath , UInt, 0x80000000 | 0x40000000 ;GENERIC_READ | GENERIC_WRITE , UInt, 0x0 ;Tries to get exclusiv rights to the drive +++(see below) , UInt, Null , UInt, 0x3 ;OPEN_EXISTING , UInt, 0x0 , UInt, NULL) if A_LastError = 32 ;In this case no handle was retreived to release { msgbox Drive is in use by another application. Please try again later return } if hVolume != -1 { DllCall("DeviceIoControl" , UInt, hVolume , UInt, 0x2D4808 ;IOCTL_STORAGE_EJECT_MEDIA , UInt, NULL , UInt, 0 , UInt, NULL , UInt, 0 , UInt, &dwBytesReturned ;Not used , UInt, NULL) DllCall("CloseHandle", UInt, hVolume) } return+++:
To throw the device out while another application reads it (like if it is open in Explorer) specify
, UInt, 0x1 ;(= FILE_SHARE_READ)
To throw the device out even while another process is writing to specify:
, UInt, 0x1 | 0x2 ;FILE_SHARE_READ | FILE_SHARE_WRITE
Edit 06.06.2006: I have added a little sample to eject a known device (for example if drive-letter changes) using it's device-ID (GUID)
Driveletter_as_value = 65 ;Begins to search at drive-letter "A". Increase this value according to your count of "fix" discs ;This loop checks the Volume-ID of all drives until the searched one is found Loop { Transform, Driveletter, Chr, %Driveletter_as_value% ;Getting a drive-letter DllCall("GetVolumeNameForVolumeMountPoint" , Str, Driveletter . ":\" , Str, GUID , UInt, 50) if (GUID = "\\?\Volume{53some83-val3-1ue9-your-drive172hasf}") ;Volume-ID of your device break else if Driveletter_as_value = 90 ;90 = "Z" as last drive-letter --> drive was not found { msgbox Device not found! return } Driveletter_as_value ++ } DrivePath = \\.\%Driveletter%: hVolume := DllCall("CreateFile" , str, DrivePath , UInt, 0x80000000 | 0x40000000 ;GENERIC_READ | GENERIC_WRITE , UInt, 0x0 ;Tries to get exclusiv rights to the drive +++(see above) , UInt, Null , UInt, 0x3 ;OPEN_EXISTING , UInt, 0x0 , UInt, NULL) if A_LastError = 32 ;In this case no handle was retreived to release { msgbox Drive is in use by another application. Please try again later return } if hVolume != -1 { DllCall("DeviceIoControl" , UInt, hVolume , UInt, 0x2D4808 ;IOCTL_STORAGE_EJECT_MEDIA , UInt, NULL , UInt, 0 , UInt, NULL , UInt, 0 , UInt, &dwBytesReturned ;Not used , UInt, NULL) DllCall("CloseHandle", UInt, hVolume) } return
Thalon