CreateSymbolicLinkA function

Creates a symbolic link.

To perform this operation as a transacted operation, use the CreateSymbolicLinkTransacted function.

Syntax

BOOLEAN CreateSymbolicLinkA(
  LPCSTR lpSymlinkFileName,
  LPCSTR lpTargetFileName,
  DWORD  dwFlags
);

Parameters

lpSymlinkFileName

The symbolic link to be created.

This parameter may include the path. In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File.

Tip  Starting with Windows 10, version 1607, for the unicode version of this function (CreateSymbolicLinkW), you can opt-in to remove the MAX_PATH limitation without prepending "\\?\". See the "Maximum Path Length Limitation" section of Naming Files, Paths, and Namespaces for details.
 

lpTargetFileName

The name of the target for the symbolic link to be created.

If lpTargetFileName has a device name associated with it, the link is treated as an absolute link; otherwise, the link is treated as a relative link.

This parameter may include the path. In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File.

Tip  Starting with Windows 10, version 1607, for the unicode version of this function (CreateSymbolicLinkW), you can opt-in to remove the MAX_PATH limitation without prepending "\\?\". See the "Maximum Path Length Limitation" section of Naming Files, Paths, and Namespaces for details.
 

dwFlags

Indicates whether the link target, lpTargetFileName, is a directory.

Value Meaning
0x0
The link target is a file.
SYMBOLIC_LINK_FLAG_DIRECTORY
0x1
The link target is a directory.
SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
0x2
Specify this flag to allow creation of symbolic links when the process is not elevated.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Symbolic links can either be absolute or relative links. Absolute links are links that specify each portion of the path name; relative links are determined relative to where relative–link specifiers are in a specified path. Relative links are specified using the following conventions:

  • Dot (. and ..) conventions—for example, "..\" resolves the path relative to the parent directory.
  • Names with no slashes (\)—for example, "tmp" resolves the path relative to the current directory.
  • Root relative—for example, "\Windows\System32" resolves to "current drive:\Windows\System32".
  • Current working directory–relative—for example, if the current working directory is C:\Windows\System32, "C:File.txt" resolves to "C:\Windows\System32\File.txt".
    Note  If you specify a current working directory–relative link, it is created as an absolute link, due to the way the current working directory is processed based on the user and the thread.
     
To remove a symbolic link, delete the file (using DeleteFile or similar APIs) or remove the directory (using RemoveDirectory or similar APIs) depending on what type of symbolic link is used.

In Windows 8 and Windows Server 2012, this function is supported by the following technologies.

Technology Supported
Server Message Block (SMB) 3.0 protocol Yes
SMB 3.0 Transparent Failover (TFO) Yes
SMB 3.0 with Scale-out File Shares (SO) No
Cluster Shared Volume File System (CsvFS) No
Resilient File System (ReFS) Yes
 

CsvFs does not support soft link or any other reparse points.

Requirements

   
Windows version Windows Vista [desktop apps only] Windows Server 2008 [desktop apps only]
Target Platform Windows
Header winbase.h (include Windows.h)
Library Kernel32.lib
DLL Kernel32.dll

See Also

CreateSymbolicLinkTransacted

File Management Functions

Symbolic Links