How to check if file is in use (Windows)

Hi!

I have a question regarding how to check if a file is in use by another program, before trying to open it for reading in data with IGOR? I have checked the WaitForFileProcs.ipf procedure file and the WaitForWriteAccesToFile function defined there which will (I think) not work in my case, because I am trying to read from a remote machine where I do not have write access and therefore the trick in the function with trying to append to file will always fail.

Are there any other options, tricks?

Thanks a lot!

Gregor
[quote]Are there any other options, tricks?[/quote]

Not that I know of. There may be some low-level way, using the Win32 API, to check if a file is open but I am not aware of it.

Other than that you would need the cooperation of the software on the other machine that is opening the file.
The GetFileFolderInfo operation provides a lot of info on a disk file, unfortunately, none of it directly answers your question. Maybe you can use something such as the returned value V_modificationDate to get an indirect answer?
Hi!

[quote]Not that I know of. There may be some low-level way, using the Win32 API, to check if a file is open but I am not aware of it.[/quote]

I briefly checked the Win32 API and the MSDN pages and it really seems that there is no direct way to check if a file is in use.

[quote]The GetFileFolderInfo operation provides a lot of info on a disk file, unfortunately, none of it directly answers your question. Maybe you can use something such as the returned value V_modificationDate to get an indirect answer?[/quote]

I will try this, probably using the file size information.

Thank you both for your quick response and help!

Cheers,
Gregor
[quote=gregorK]Hi!

I briefly checked the Win32 API and the MSDN pages and it really seems that there is no direct way to check if a file is in use.

[/quote]

Shouldn't LockFileEx[1] with LOCKFILE_EXCLUSIVE_LOCK set accomplish that?
As far as I understand it, you will only get an exclusive lock if no other process has already locked the file.

[1]: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365203%28v=vs…