Check if file is locked by another process via LotusScript

Hello all,

is it possible to check on the Notes Client (platform is Win/32) via LotusScript if a file is locked by another process? I have to do this in my application before the file is killed.

Thanks in advance for your help!

Subject: Well…

if you’re going to kill the file anyway, just use an error handler. If the file is indeed locked by something else, the kill will fail and throw an error, which you can handle. That’s your check. There are more elaborate ways to do this via the Win API, but this might work just fine.

Thomas - IBM

Subject: Which Win- API-function

Hello Thomas,

thank you very much for your answer. In this case you are very right - the errorhandling is the check. Thanks again.

But do you know which Win-API-function could handle this? I searched some forums but I couldn’t find the proper thing. This would be intersting for me in another case.

Best regards

Andi

Subject: RE: Which Win- API-function

You would use LockFile for that. You don’t actually lock a file, but a byte range within a file, so if you want to know if any byte in a file is locked then you would use offset 0 and the size of the file as the range. Afterward, use UnlockFile to remove the lock.

However, be aware that this isn’t just checking for a lock, it actually performs a lock. So if another process attempted to do a lock during your check, it will fail.