Click to Rate and Give Feedback
MSDN
MSDN Library
System Services
File Services
File Systems
File Management
 CreateSymbolicLink Function
CreateSymbolicLink Function

Creates a symbolic link.

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

Syntax

C++
BOOLEAN WINAPI CreateSymbolicLink(
  __in  LPTSTR lpSymlinkFileName,
  __in  LPTSTR lpTargetFileName,
  __in  DWORD dwFlags
);

Parameters

lpSymlinkFileName [in]

The symbolic link to be created.

lpTargetFileName [in]

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.

dwFlags [in]

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

ValueMeaning
0x0

The link target is a file.

SYMBOLIC_LINK_FLAG_DIRECTORY
0x1

The link target is a directory.

 

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.

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

Unicode and ANSI names

CreateSymbolicLinkW (Unicode) and CreateSymbolicLinkA (ANSI)

See Also

CreateSymbolicLinkTransacted
File Management Functions
Symbolic Links

 

 

Send comments about this topic to Microsoft

Build date: 2/4/2010

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
How to remove?      Jos ... Noelle Mallory - MSFT   |   Edit   |   Show History

And how do you remove a symbolic link?

There seems to be no function RemoveSymbolicLink or DeleteSymbolicLink.

[Noelle Mallory - MSFT] Please post questions to the MSDN Forums at http://forums.microsoft.com/msdn. You will likely get a quicker response through the forum than through the Community Content.

Re: removing symbolic links      zhenya1007   |   Edit   |   Show History
c.f. DeleteFile() documentation
Tags What's this?: Add a tag
Flag as ContentBug
vb.net syntax      dmex ... Đonny   |   Edit   |   Show History
<DllImport("kernel32.dll", EntryPoint:="CreateSymbolicLinkW", CharSet:=CharSet.Unicode)> _
Public Shared Function CreateSymbolicLink(<[In]()> ByVal lpSymlinkFileName As String, <[In]()> ByVal lpTargetFileName As String, <[In]()> ByVal dwFlags As Integer) As Integer
End Function

or

Private Declare Auto Function CreateSymbolicLink Lib "kernel32.dll" ( _
<[In](), MarshalAs(UnmanagedType.LPTStr)> ByVal lpSymlinkFileName As String, _
<[In](), MarshalAs(UnmanagedType.LPTStr)> ByVal lpTargetFileName As String, _
<[In]()> ByVal dwFlags As Integer) As Boolean
C# syntax      dmex   |   Edit   |   Show History
[DllImport("kernel32.dll", EntryPoint="CreateSymbolicLinkW", CharSet=CharSet.Unicode)]
public static extern int CreateSymbolicLink([In] string lpSymlinkFileName, [In] string lpTargetFileName, int dwFlags);
Tags What's this?: c# (x) syntax (x) Add a tag
Flag as ContentBug
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker