函数参考


_WinAPI_CreateHardLink

Establishes a hard link between an existing file and a new file.

#Include <WinAPIEx.au3>
_WinAPI_CreateHardLink ( $sNewFile, $sExistingFile )

参数

$sNewFile The name of the new file.
$sExistingFile The name of the existing file.

返回值

成功: 返回 1.
失败: 返回 0 并设置 @error 标志为非 0 值.

注意/说明

The _WinAPI_CreateHardLink() is only supported on the NTFS file system, and only for files, not directories.

The security descriptor belongs to the file to which a hard link points. The link itself is only a directory entry,
and does not have a security descriptor. Therefore, when you change the security descriptor of a hard link, you
a change the security descriptor of the underlying file, and all hard links that point to the file allow the newly
specified access. You cannot give a file different security descriptors on a per-hard-link basis.

Use _WinAPI_DeleteFile() function to delete hard links. You can delete them in any order regardless of the
order in which they are created.

相关

详情参考

在MSDN中搜索


示例/演示


#Include <APIConstants.au3>
#Include <Array.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global Const $sFile = @DesktopDir & '\' & StringRegExpReplace(_WinAPI_PathFindFileName(@ScriptName), '\A_+', '@')

Global $aData

; Create hard link to the current file with prefix "@" on your Desktop
_WinAPI_CreateHardLink($sFile, @ScriptFullPath)
If @error Then
    MsgBox(16, 'Error', 'Unable to create hard link.')
    Exit
EndIf

; Enumerate all hard links to the file
$aData = _WinAPI_EnumHardLinks($sFile)

_ArrayDisplay($aData, '_WinAPI_EnumHardLinks')

FileDelete($sFile)