Bob Wya Posted August 8, 2007 Share Posted August 8, 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...
phew Posted August 8, 2007 Share Posted August 8, 2007 i'm voting for a (time) ban. or any good excuse why multiposting your thread 4 times? Link to comment Share on other sites More sharing options...
Developers Jos Posted August 8, 2007 Developers Share Posted August 8, 2007 (edited) i'm voting for a (time) ban.Agree ... dups removed Edited August 8, 2007 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
herewasplato Posted August 8, 2007 Share Posted August 8, 2007 Agree ... dups removedThere were more than 4 dupsYou might want to also delete these:http://www.autoitscript.com/forum/index.ph...&pid=385421http://www.autoitscript.com/forum/index.ph...&pid=385411http://www.autoitscript.com/forum/index.ph...&pid=385405-MSP- [size="1"][font="Arial"].[u].[/u][/font][/size] 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