function IsFileInUse(fName : string) : boolean; <br>var <br>HFileRes : HFILE; <br>begin <br>Result := false; <br>if not FileExists(fName) then <br>exit; <br>HFileRes := CreateFile(pchar(fName), GENERIC_READ or GENERIC_WRITE, <br>0 {this is the trick!}, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); <br>Result := (HFileRes = INVALID_HANDLE_VALUE); <br>if not Result then <br>CloseHandle(HFileRes); <br>end; <br>