#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
Global $Text, $Type, $Drive = DriveGetDrive('CDROM')
If IsArray($Drive) Then
For $i = 1 To $Drive[0]
$Text = 'Unknown'
$Type = _WinAPI_GetCDType($Drive[$i])
If Not @error Then
Switch $Type
Case 0x0000
$Text = 'No media'
Case 0x0008
$Text = 'CD-ROM'
Case 0x0009
$Text = 'CD-R'
Case 0x000A
$Text = 'CD-RW'
Case 0x0010
$Text = 'DVD-ROM'
Case 0x0011
$Text = 'DVD-R SR'
Case 0x0012
$Text = 'DVD-RAM'
Case 0x0013
$Text = 'DVD-RW RO'
Case 0x0014
$Text = 'DVD-RW SR'
Case 0x0015
$Text = 'DVD-R DL'
Case 0x0016
$Text = 'DVD-R DL JR'
Case 0x0017
$Text = 'DVD-RW DL'
Case 0x0018
$Text = 'DVD-DDR'
Case 0x001A
$Text = 'DVD+RW'
Case 0x001B
$Text = 'DVD+R'
Case 0x0040
$Text = 'BD-ROM'
Case 0x0041
$Text = 'BD-R SRM'
Case 0x0042
$Text = 'BD-R RRM'
Case 0x0043
$Text = 'BD-RE'
Case 0x0050
$Text = 'HD DVD-ROM'
Case 0x0051
$Text = 'HD DVD-R'
Case 0x0052
$Text = 'HD DVD-RAM'
Case 0x0053
$Text = 'HD DVD-RW'
Case 0x0058
$Text = 'HD DVD-R DL'
Case 0x005A
$Text = 'HD DVD-RW DL'
EndSwitch
EndIf
ConsoleWrite(StringUpper($Drive[$i]) & ' => ' & $Text & @CR)
Next
EndIf
; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_GetCDType
; Description....: Retrieves a type of the media which is loaded into a specified CD-ROM device.
; Syntax.........: _WinAPI_GetCDType ( $sDrive )
; Parameters.....: $sDrive - The drive letter of the CD tray to retrieve information, in the format D:, E:, etc.
; Return values..: Success - The type of the media, it must be one of the following values.
;
; 0x0000 - No media
; 0x0008 - CD-ROM
; 0x0009 - CD-R
; 0x000A - CD-RW
; 0x0010 - DVD-ROM
; 0x0011 - DVD-R Sequential Recording
; 0x0012 - DVD-RAM
; 0x0013 - DVD-RW Restricted Overwrite
; 0x0014 - DVD-RW Sequential Recording
; 0x0015 - DVD-R Dual Layer
; 0x0016 - DVD-R Dual Layer Jump Recording
; 0x0017 - DVD-RW Dual Layer
; 0x0018 - DVD-Download Disc Recording
; 0x001A - DVD+RW
; 0x001B - DVD+R
; 0x0040 - BD-ROM
; 0x0041 - BD-R Sequential Recording Mode (SRM)
; 0x0042 - BD-R Random Recording Mode (RRM)
; 0x0043 - BD-RE
; 0x0050 - HD DVD-ROM
; 0x0051 - HD DVD-R
; 0x0052 - HD DVD-RAM
; 0x0053 - HD DVD-RW
; 0x0058 - HD DVD-R Dual Layer
; 0x005A - HD DVD-RW Dual Layer
; 0xFFFF - Unknown
;
; Failure - 0 and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: None
; Related........:
; Link...........: @@MsdnLink@@ IOCTL_SCSI_PASS_THROUGH
; Example........: Yes
; ===============================================================================================================================
Func _WinAPI_GetCDType($sDrive)
Local $hFile = _WinAPI_CreateFileEx('\\.\' & $sDrive, 3, 0xC0000000, 0x03)
If Not $hFile Then
Return SetError(1, 0, 0)
EndIf
Local $tSPT = DllStructCreate('ushort Length;byte ScsiStatus;byte PathId;byte TargetId;byte Lun;byte CdbLength;byte SenseInfoLength;byte DataIn;byte Alignment[3];ulong DataTransferLength;ulong TimeOutValue;ulong_ptr DataBufferOffset;ulong SenseInfoOffset;byte Cdb[16];byte Hdr[8]')
Local $tCDB = DllStructCreate('byte;byte;byte[2];byte[3];byte[2];byte;byte[2];byte[4]', DllStructGetPtr($tSPT, 'Cdb'))
Local $tHDR = DllStructCreate('byte[4];byte;byte;byte[2]', DllStructGetPtr($tSPT, 'Hdr'))
Local $Size = DllStructGetSize($tSPT) - 8
DllStructSetData($tSPT, 'Length', $Size)
DllStructSetData($tSPT, 'ScsiStatus', 0)
DllStructSetData($tSPT, 'PathId', 0)
DllStructSetData($tSPT, 'TargetId', 0)
DllStructSetData($tSPT, 'Lun', 0)
DllStructSetData($tSPT, 'CdbLength', 12)
DllStructSetData($tSPT, 'SenseInfoLength', 0)
DllStructSetData($tSPT, 'DataIn', 1)
DllStructSetData($tSPT, 'DataTransferLength', 8)
DllStructSetData($tSPT, 'TimeOutValue', 30)
DllStructSetData($tSPT, 'DataBufferOffset', $Size)
DllStructSetData($tSPT, 'SenseInfoOffset', 0)
DllStructSetData($tCDB, 1, 0x46)
DllStructSetData($tCDB, 2, 0)
DllStructSetData($tCDB, 3, 0, 1)
DllStructSetData($tCDB, 3, 0, 2)
DllStructSetData($tCDB, 5, 0, 1)
DllStructSetData($tCDB, 5, 8, 2)
DllStructSetData($tCDB, 6, 0)
DllStructSetData($tCDB, 7, 0, 1)
DllStructSetData($tCDB, 7, 0, 2)
Local $Ret = DllCall('kernel32.dll', 'int', 'DeviceIoControl', 'ptr', $hFile, 'dword', $IOCTL_SCSI_PASS_THROUGH, 'ptr', DllStructGetPtr($tSPT), 'dword', $Size, 'ptr', DllStructGetPtr($tSPT), 'dword', DllStructGetSize($tSPT), 'dword*', 0, 'ptr', 0)
If (@error) Or (Not $Ret[0]) Then
$Ret = 0
EndIf
_WinAPI_CloseHandle($hFile)
If Not IsArray($Ret) Then
Return SetError(2, 0, 0)
EndIf
Return BitOR(BitShift(DllStructGetData($tHDR, 4, 1), -8), DllStructGetData($tHDR, 4, 2))
EndFunc ;==>_WinAPI_GetCDType