Archive: File Write Access check wont always work..


File Write Access check wont always work..
Hi!
I use this method to check if I can start overwriting a exe:
-----------
StrCpy $1 0

loop:
FileOpen $0 "$EXEDIR\MYEXE.EXE" "w"
IfErrors 0 done
IntOp $1 $1 + 1
IntCmpU $1 50 done 0 done # if we got to 50 or passed it, enough
Sleep 500 # wait for 500ms
Goto loop
done:
FileClose $0

File "MYEXE.EXE"
------------
Sometimes it works fine, but sometimes it doesn't. The EXE is suddenly 0 KB in size...

Any ideas?

Thanks!


Try removing the sleep bit. Maybe having sleep there is stopping FileOpen seeing the file as writable.

-Stu


If you want to try whether you can overwrite, you can also use SetOverwrite try and check the error flag.


Thanks for the replies.
SetOverwrite Try - worked just fine, TY!!

Here is what I got in the end..

----------
Loop:
File "MYEXE.EXE"

IfErrors 0 Done
IntOp $1 $1 + 1
IntCmpU $1 50 Error 0 Done # if we got to 50 or passed it, enough
Sleep 500 # wait for 500ms
ClearErrors
GoTo Loop

Error:
MessageBox MB_OK|MB_ICONSTOP "Error message!"

Done:
--------------

Thanks again for the replies!


Just so you'll know next time, if the file was emptyed it means FileOpen didn't fail. You probably got an error because you didn't clean the error flag before you called FileOpen, and there was an error somewhere before FileOpen. It failed to reopen the file and looped 50 times because you only close the file after the loop is finished.


Before loop, put ClearErrors (if you haven't already!)

-Stu