windowswinapicreatefilewindows-kernel

Is it relevant for CreateFile whether other handles to the same file have been opened by the same or a different process?


When working with filesystem files on Windows, and specifically with the CreateFile API:

With regard to access sharing, that is having multiple, independent, CreateFile calls to open the same file, possibly with different flags and sharing modes, does it matter in any way whether file access is performed from within the same process or from a different process?

That is, once someone has opened a file with CreateFile(..., FILE_SHARE_READ, ...), noone should be able to open the same file with GENERIC_WRITE access. Does it matter whether different calls originate from within the same process, or from different processes?

My impression so far is that process boundaries do not matter for independent CreateFile calls to the same file. (They do matter for handle inheritance, etc.)

But that docs contain such gems as:

To enable a process to share a file or device while another process has the file or device open, use a compatible combination of one or more of the following values. For more information about valid combinations of this parameter with the dwDesiredAccess parameter, see Creating and Opening Files.

which doesn't exactly inspire confidence.


Solution

  • No. In general such access restrictions to files don't care if they are done from the same or different process.

    The file sharing flags work always the same way.