Creates a symbolic link.
#Include <WinAPIEx.au3>
_WinAPI_CreateSymbolicLink ( $sSymlink, $sTarget [, $fDirectory] )
$sSymlink | The name of the new file. |
$sTarget | The name of the existing file. |
$fDirectory | [可选参数] Specifies whether the link target is a directory. TRUE - The link target is a directory. FALSE - The link target is a file. (Default) |
成功: | 返回 1. |
失败: | 返回 0 并设置 @error 标志为非 0 值. |
在MSDN中搜索
#Include <APIConstants.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
If _WinAPI_GetVersion() < '6.0' Then
MsgBox(16, 'Error', 'Require Windows Vista or later.')
Exit
EndIf
Global $hToken, $aAdjust
; Enable "SeCreateSymbolicLinkPrivilege" privilege to create a symbolic links
$hToken = _WinAPI_OpenProcessToken(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY))
_WinAPI_AdjustTokenPrivileges($hToken, $SE_CREATE_SYMBOLIC_LINK_NAME, $SE_PRIVILEGE_ENABLED, $aAdjust)
If @error Or @extended Then
MsgBox(16, 'Error', 'You do not have the required privileges.')
Exit
EndIf
; Create symbolic link to the directory where this file is located with prefix "@" on your Desktop
_WinAPI_CreateSymbolicLink(@DesktopDir & '\' & StringRegExpReplace(@ScriptDir, '^.*\\', '@'), @ScriptDir, 1)
If @error Then
_WinAPI_ShowLastError()
EndIf
; Restore "SeCreateSymbolicLinkPrivilege" privilege by default
_WinAPI_AdjustTokenPrivileges($hToken, $aAdjust, 0, $aAdjust)
_WinAPI_CloseHandle($hToken)