Any directory entry for a file, whether created with CreateFile or
CreateHardLink, is a hard link to the associated file. Additional hard links,
created with the CreateHardLink function, allow you to have multiple directory
entries for a file, that is, multiple hard links to the same file. These may
be different names in the same directory, or they may be the same (or
different) names in different directories. However, all hard links to a file
must be on the same volume.
Because hard links are just directory entries for a file, whenever an
application modifies a file through any hard link, all applications using any
other hard link to the file see the changes. Also, all of the directory
entries are updated if the file changes. For example, if the file's size
changes, all of the hard links to the file will show the new size.
The security descriptor belongs to the file to which the hard link points.
The link itself, being merely a directory entry, has no security descriptor.
Thus, if you change the security descriptor of any hard link, you're actually
changing the underlying file's security descriptor. All hard links that point
to the file will thus allow the newly specified
access. There is no way to
give a file different security descriptors on a per-hard-link basis.
This function does not modify the security descriptor of the file to be linked
to, even if security descriptor information is passed in the
lpSecurityAttributes parameter.
Use DeleteFile to delete hard links. You can delete them in any order
regardless of the order in which they were created.
Flags, attributes,
access, and sharing as specified in CreateFile operate on
a per-file basis. That is, if you open a file with no sharing allowed, another
application cannot share the file by creating a new hard link to the file.
CreateHardLink does not work over the network redirector.
Note that when you create a hard link on NTFS, the file attribute information
in the directory entry is refreshed only when the file is opened or when
GetFileInformationByHandle is called with the
handle of the file of interest.