
The OpenSounds() function is called quite early on in the script. From this I deduced that something being executed during the startup of the script was the cause of the locking handle.
COMMENT UTILISER IVOLUME CODE
The weird thing is the exact code works if you delete the temp files before running the script but then breaks again when you close and open the script without deleting the files. Func AddOneUntil100 ( ByRef $iNumber ) $iNumber += 1 If $iNumber = 100 Then Return True Else Return False EndIf EndFunc $iNumber = 0 While Not (AddOneUntil100 ( $iNumber ) ) ConsoleWrite ( $iNumber & ) WEnd ConsoleWrite ( "$iNumber = " & $iNumber & "!" & )Īlso I've come to realise that there's something else in my script causing autoit keeping a locking handle on the file. The thing about it getting stuck in the while statement is wrong because the statement is executed in each loop.

In fact I did that batch file method in other places in my script so this is great. The problem still occurs with the new code but at least it's a little more efficient now. Occasionally, even though I closed all the sound handles, Autoit still has a locking handle on the sound files. I'm changing the volume of some audio files using a command line audio editor called SoX.

OpenSounds ( ) EndFunc Func OpenSounds ( ) Global $aSndStart = _SoundOpen & "\Sound\tempBeep-01.wav" ) Global $aSndStop = _SoundOpen & "\Sound\tempBeep-02.wav" ) Global $aSndHotkey = _SoundOpen & "\Sound\tempBeep-03.wav" ) Global $aSndError = _SoundOpen & "\Sound\tempBeep-04.wav" ) Global $aSndHotkeyToggle = _SoundOpen & "\Sound\Beep-05.wav" ) EndFunc Func CloseSounds ( ) _SoundClose ( $aSndStart ) _SoundClose ( $aSndStop ) _SoundClose ( $aSndHotkey ) _SoundClose ( $aSndError ) _SoundClose ( $aSndHotkeyToggle ) EndFunc

Expand collapse popup Func SetVolume ( $iVolume )ĬloseSounds ( ) $fVolume = $iVolume / 100 $hVolumeFile = FileOpen ( "Volume.bat", 2 ) For $i = 1 To 5 FileWriteLine ( $hVolumeFile, '"' & & '\sox\sox.exe" "' & & '\Sound\Beep-0' & $i & '.wav" "' & & '\Sound\tempBeep-0' & $i & '.wav" vol ' & $fVolume ) Next FileClose ( $hVolumeFile ) While Not ( FileDelete & "\Sound\tempBeep-01.wav" ) ) Sleep ( 50 ) WEnd While Not ( FileDelete & "\Sound\tempBeep-02.wav" ) ) Sleep ( 50 ) WEnd While Not ( FileDelete & "\Sound\tempBeep-03.wav" ) ) Sleep ( 50 ) WEnd While Not ( FileDelete & "\Sound\tempBeep-04.wav" ) ) Sleep ( 50 ) WEnd While Not ( FileDelete & "\Sound\tempBeep-05.wav" ) ) Sleep ( 50 ) WEnd $hPid = Run ( "Volume.bat", , ) While ProcessExists ( $hPid ) Sleep ( 10 ) WEnd
