Jump to content
Sign in to follow this  
Bob Wya

Problem with SCSI access routines to DVD/CD drives

Recommended Posts

Bob Wya


I am using some routines that were posted here a while back for accessing DVD / CD drives through the Windows SCSI interace to allow low level access

(e.g. to determine tray status, etc.)

I include the routines (all functions in a attached file, the open drive handle code in a code box - see below)...NB they have been slightly basterdised by me but are essentially the same!!

The code works very well except for a slight problem! The problem is that the DLL call to open the volume handle to an optical drive leaves a $hVolume READ/WRITE handle open to the optical drive with a file handle like \Device\CdRom0 showing up in ProcessExplorer (no FileClose doesn't work!!) This unfortunately locks other applications out of the drive. If I close this handle manually in ProcessExplorer then problem solved!! Question is how do I write a DLL call to close this handle?? I presume it is similar to the DLL call to create the handle in the first place but I still getting my head around this sort of thing...

Thanks for any help you guys can give!!

Bob Wya

Func OpenVolume($cDriveLetter)

Local $a_controls

; From AUTOIT forums

Local $hVolume, $uDriveType, $szVolumeName, $dwAccessFlags

If StringLen($cDriveLetter) = 1 Then

$cDriveLetter = $cDriveLetter & ":"

ElseIf StringLen($cDriveLetter) = 2 Then

;do nothing

ElseIf StringLen($cDriveLetter) = 3 Then

$cDriveLetter = StringLeft($cDriveLetter, 2)




Local $szRootName = $cDriveLetter & "\"

$uDriveType = DriveGetType($szRootName)


Case $uDriveType == "Removable"


Case $uDriveType == "CDROM"

;We need write access in order to send scsi commands.


;$dwAccessFlags = $GENERIC_READ

Case Else



$szVolumeName = "\\.\" & $cDriveLetter & ""

;$szVolumeName = "\\.\CdRom0"

;in addition to getting the handle, the following also verifies write access, which is required to use the scsi pass through

$hVolume = DllCall( _

"kernel32.dll", "hwnd", _

"CreateFile", _

"str", $szVolumeName, _

"long", $dwAccessFlags, _


"ptr", 0, _

"long", $OPEN_EXISTING, _

"long", 0, _

"long", 0 _


If @error Then



Return $hVolume[0]


EndFunc ;==>OpenVolume

Share this post

Link to post
Share on other sites
Bob Wya

ProcessClose perhaps?

Na that won't work - its not a process mate!! CloseHandle from the "AutoLib3" AutoIt extension does the job though!!

Thanks anyway!!


Share this post

Link to post
Share on other sites

Hopefully you found the solution, but my original script used the wrong datatype on a call related to the drive handle. See the original thread here:


And search thread for the text "fix for the drive", which points to this thread with discussion of the bug:


Again, thanks to garyfrost for the fix.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this