A-Z List


Mklink

Updated: April 17, 2012

Applies To: Windows Server 2008, Windows Vista

Creates a symbolic link.

For examples of how to use this command, see Examples.

Syntax

mklink [[/d] | [/h] | [/j]] <Link> <Target>
Parameters

 

Parameter Description

/d

Creates a directory symbolic link. By default, mklink creates a file symbolic link.

/h

Creates a hard link instead of a symbolic link.

/j

Creates a Directory Junction.

<Link>

Specifies the name of the symbolic link that is being created.

<Target>

Specifies the path (relative or absolute) that the new symbolic link refers to.

/?

Displays help at the command prompt.

Examples

To create a symbolic link named MyDocs from the root directory to the \Users\User1\Documents directory, type:

mklink /d \MyDocs \Users\User1\Documents

Tags :


Community Content

TLee4158
Can I create a symbolic links pointing an online file ?
<p><span><span>What about the case when the http URL points to a WebDav server and the Microsoft Webdav Client/Redirector is running?  Shouldn't this work since the WebDav client should handle all the http path parsing issues?  </span></span><br /></p><p><span>From my own testing I can say that it seems to work for most things.  However I do run into a problem when accessing the symlink with Explorer especially when doing a right-click on the link.   Quite often Explorer ends up becoming unresponsive and I end up having to hard reboot the machine to get things back to normal. <br /></span><br />I <span>should also mention that I am actually first mapping a drive (i.e. Z:) using the http path (i.e. net use Z: "http://server/dav") and then using the Z:/&lt;filename&gt; as the target to the mklink command.  Shouldn't this work?  If I access files or right-click them from the Z: drive directly it always seems to work with no Explorer hang.   BUT if I do the same thru the symlink it sometimes works, but frequently I'll see Explorer get into the unresponsive state I mentioned above.<br /></span><span><br /></span><span>If I do the same thing with a CIFS UNC path it always works which leads me to think there is a bug in the WebDav client.  But when I opened an incident with MS support they referred me to this page and said things were "working as designed".  Thought I would mention this here in hopes of getting more information from experts or possibly getting the ball rolling to fix the WebDav client so that the Explorer hang issues get resolved.  We would really like to be able to use this functionality if it could work reliably.<br /></span></p><p><span><em>Can I create a symbolic link pointing an online file? (Like... an web located file, for example.) If the answer is yes, how?</em></span><br /><em><br /></em><em>Short answer, yes, you could create it, since the symbolic link creation process does not evaluate what is stored in the link for validity as a file reference, just that it is a string of &gt;0 length. Thus you could store in a symbolic link a value like ftp:// or <mtps:InstrumentedLink NavigateUrl="" runat="server" xmlns:mtps="http://msdn2.microsoft.com/mtps">http:// www.mywebsite.com/myfile.txt</mtps:InstrumentedLink> (which I presume is the type of 'web located' reference you're referring to) and mklink won't complain. </em><br /></p><em><!----></em><p><em>When you do a file operation on a path that link is part of, however, that operation will most likely fail because no drive mount or network share will match the "http:" portion of the reference. It might succeed if some 3rd party kernel mode driver that extends the path parsing process is installed, but I don't know of any that do so. To make such a driver so that it would be transparent to current applications would require doing the equivalent of SetProcAddress on multiple kernel and user mode APIs, many of which are not exports from their app or library modules to begin with, to replace all the code where paths are checked for validity. I suspect rather than doing this so multi-letter drive designators could be recognized, MS opted to implement the directory form of volume mounts for NTFS as the easier alternative.<br /></em></p><p><em /><em>To setup a symbolic or hard link to another computer over the internet that has a chance of being useful you have to establish and reference a VPN connection through the share name associated with it, be it a drive letter or UNC type name, and setup LAN Manager so it would report that connection as equivalent to a local file. Whether that would also require an add-on I'm not sure of, but such an add-on would be nominally easier to write.</em></p>
Tags :

merv_f
Root Relative Symbolic Links Not Resolving Properly
It's nice that this example uses a root relative symlink, but if you try a slightly different example you'll begin to see some problems.  Example: $0$0 $0 $0<span> $0mklink /d \Temp\MyDocs \Users\User1\Documents$0 </span>$0 $0$0 $0 $0The link itself works fine when you try to follow it (double-click from Explorer).  However, if you open the <strong>Properties </strong>window (from the context menu) of the symlink, you can't navigate to other tabs because the root relative link is resolved as directory relative in the text box for the <strong>Target</strong>.$0 $0$0 $0 $0Seems like a bug.  The only reason this doesn't show up in the example on in the docs is that the symlink is created in the root directory to begin with.$0
Tags :

TwelveBaud
Hard links only work on files, not directories.
Hard links only work for files, not directories. <div><br /></div><div>Where's the official documentation to support this?<br /><br /><i>Hard links create a new "filename" entry for a particular file in the Master File Table. Technically, there's no reason you couldn't say that a directory has a second "filename" it can be accessed by. However, none of the files underneath that directory would pick up the new name: they'd still only have one MFT entry. Chkdsk would most likely flag this as an error, delete both instances of the directory, and rebuild it from scratch, undoing your efforts.</i><br /></div>
Tags :

G1
Remove a symbolic link
remove symbolic file link<br /><br />del &lt;link-name&gt;<br /><br />remove symbolic directory link<br /><br />rmdir &lt;link-name&gt;
Tags :

Mr Ziggy
Can I create a symbolic links pointing an online file ?
Can I create a symbolic link pointing an online file? (Like... an web located file, for example.) If the answer is yes, how?<br /><br />Short answer, yes, you could create it, since the symbolic link creation process does not evaluate what is stored in the link for validity as a file reference, just that it is a string of &gt;0 length. Thus you could store in a symbolic link a value like ftp:// or <mtps:InstrumentedLink NavigateUrl="" runat="server" xmlns:mtps="http://msdn2.microsoft.com/mtps">http:// www.mywebsite.com/myfile.txt</mtps:InstrumentedLink> (which I presume is the type of 'web located' reference you're referring to) and mklink won't complain. <br /><br />When you do a file operation on a path that link is part of, however, that operation will most likely fail because no drive mount or network share will match the "http:" portion of the reference. It might succeed if some 3rd party kernel mode driver that extends the path parsing process is installed, but I don't know of any that do so. To make such a driver so that it would be transparent to current applications would require doing the equivalent of SetProcAddress on multiple kernel and user mode APIs, many of which are not exports from their app or library modules to begin with, to replace all the code where paths are checked for validity. I suspect rather than doing this so multi-letter drive designators could be recognized, MS opted to implement the directory form of volume mounts for NTFS as the easier alternative.<br /><br />To setup a symbolic or hard link to another computer over the internet that has a chance of being useful you have to establish and reference a VPN connection through the share name associated with it, be it a drive letter or UNC type name, and setup LAN Manager so it would report that connection as equivalent to a local file. Whether that would also require an add-on I'm not sure of, but such an add-on would be nominally easier to write.

Bigou
Can I create a symbolic link pointing on internet?
Can I create a symbolic link pointing an online file? (Like... an web located file, for example.) If the answer is yes, <span lang="en"><span title="Cliquer ici pour voir d'autres traductions">how</span><span title="Cliquer ici pour voir d'autres traductions">?</span></span>

SunlightD
For non-admins
<p>Hard links (/H) and junctions (/J) do not require SeCreateSymbolicLink, so can be run without elevation.</p>
Tags :

gavin.zhao
To get admin privileges
pls enter the folder %systemroot%/system32, find cmd.exe, then right click and choose "run as an administrator" (sth. like that), mklink will run well in this cmd window.<br /><br /><br /><br />
Tags :

Petr Kadlec
SeCreateSymbolicLinkPrivilege is required
Creation of symbolic links requires the SeCreateSymbolicLinkPrivilege (“Create symbolic links”), which is granted only to administrators by default (but you can change that using security policy). The stated reason for this requirement is: “This user right should only be assigned to trusted users. Symbolic links (symlinks) can expose security vulnerabilities in applications that aren't designed to handle symbolic links.” (See secpol.msc, or <mtps:InstrumentedLink NavigateUrl="http://technet.microsoft.com/en-us/library/cc766301(WS.10).aspx" runat="server" xmlns:mtps="http://msdn2.microsoft.com/mtps">http://technet.microsoft.com/en-us/library/cc766301(WS.10).aspx</mtps:InstrumentedLink>)
Tags :

Red!
Why higher privileges might be needed
<p>I was testing an application which checked it's home running directory (it seems anyway) to know wether it's running; copying it to another directory worked in making the application start another process.</p> <p>I though it would be clever to make a link to "sub" to "." (which actually works perfectly fine; and the application ran multiple times too), however when browsing in Explorer, for some reason it keeps expanding the infinite loop of symlinks! I even tried isolating the symlink in real directory; it still expanded it on it's own for unknown reasons.</p> <p>So my guess is since it's so easy for someone to accidently do this, they wanted to protect "normal" users from using this - specially if using older applications unaware of the possibility of infinite loops...</p>
Tags :

Thomas Lee
Why does this require admin privileges to run?
I am trying to run it in a directory where even a non-elevated user is allowed to write.

Thomas Lee
Genghis86 asks a good question
No idea why it required admin privileges but it might be to do with the confusion that making a hard link could cause. It doesn't seem that illogical (do you really want users making hard links everywhere which could cause backup loops, etc?). MS has always been a little shy over this feature, but I think I agree that if you have full control over a folder you should be able to mklink in that folder to another folder you also have access to.<p> </p><p>At a very minimum, MS should explain this feature and why it's privileged.<br /></p><br />

Page view tracker