Sign in to follow this  
Followers 0
Bob Wya

Problem with SCSI access routines to DVD/CD drives

4 posts in this topic

Hi

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

CODE
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)

Else

Return $INVALID_HANDLE_VALUE

EndIf

Local $szRootName = $cDriveLetter & "\"

$uDriveType = DriveGetType($szRootName)

Select

Case $uDriveType == "Removable"

$dwAccessFlags = BitOR($GENERIC_READ, $GENERIC_WRITE)

Case $uDriveType == "CDROM"

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

$dwAccessFlags = BitOR($GENERIC_READ, $GENERIC_WRITE)

;$dwAccessFlags = $GENERIC_READ

Case Else

Return $INVALID_HANDLE_VALUE

EndSelect

$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, _

"long", BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), _

"ptr", 0, _

"long", $OPEN_EXISTING, _

"long", 0, _

"long", 0 _

)

If @error Then

Return $INVALID_HANDLE_VALUE

Else

Return $hVolume[0]

EndIf

EndFunc ;==>OpenVolume

Share this post


Link to post
Share on other sites



i'm voting for a (time) ban.

or any good excuse why multiposting your thread 4 times?

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  
Followers 0