Balder
3rd May 2003 21:58 UTC
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!
Afrow UK
3rd May 2003 22:04 UTC
Try removing the sleep bit. Maybe having sleep there is stopping FileOpen seeing the file as writable.
-Stu
Joost Verburg
3rd May 2003 22:20 UTC
If you want to try whether you can overwrite, you can also use SetOverwrite try and check the error flag.
Balder
3rd May 2003 23:29 UTC
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!
kichik
7th May 2003 15:06 UTC
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.
Afrow UK
7th May 2003 15:59 UTC
Before loop, put ClearErrors (if you haven't already!)
-Stu