Bob Wya Posted August 9, 2007 Share Posted August 9, 2007 HiI 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 WyaCODEFunc 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] EndIfEndFunc ;==>OpenVolume Link to comment Share on other sites More sharing options...
Bert Posted August 9, 2007 Share Posted August 9, 2007 ProcessClose perhaps? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bob Wya Posted August 12, 2007 Author Share Posted August 12, 2007 ProcessClose perhaps?Na that won't work - its not a process mate!! CloseHandle from the "AutoLib3" AutoIt extension does the job though!!Thanks anyway!!Bob Link to comment Share on other sites More sharing options...
bhoar Posted November 14, 2007 Share Posted November 14, 2007 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: http://www.autoitscript.com/forum/index.php?showtopic=28326And search thread for the text "fix for the drive", which points to this thread with discussion of the bug: http://www.autoitscript.com/forum/index.php?showtopic=39368Again, thanks to garyfrost for the fix.-brendan Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now