How to determine a file is in-use
Hi,
Can anyone provides help on How to determine a file is in-use?
Thanks,
Roger
Archive: How to determine a file is in-use
How to determine a file is in-use
Hi,
Can anyone provides help on How to determine a file is in-use?
Thanks,
Roger
one probably not so good way to do it would be to call CreateFile (with write access) using the system plugin
in CreateFile also set dwCreationDisposition to CREATE_NEW - otherwise this may open existing file "in-use" if FILE_SHARE_WRITE mode was set by another application.
I'd use FileOpen.
E.g.
Push $R0
ClearErrors
FileOpen $R0 "file.ext" r
FileClose $R0
IfErrors 0 +2
DetailPrint "file.ext is locked!"
Pop $R0
2 Afrow UK
BTW 2 programs can open and read the same file if "share read" permission was used on file open (in Windows too :) ). Most likelly NSIS uses the same CreateFile API call for FileOpen implementation, and FILE_SHARE_READ flag presents in calls I can see in nsis\source code.