MKLink – Windows CMD Command

Create a symbolic link to a directory or a file, or create a hard file link or directory junction.

Types of Link

Can link to files?Can link to folders?Can link across hard drives?Supported on:Can point to a non-existent target?Can be relative?How to delete:
ShortcutYesYesYesWindows 95+YesNoDel
Hard linkYesNoNoWindows 3.5+No
NoDel
Junction
(soft link)
NoYesY (on the same computer)Windows 2000+YesNoRD
Symbolic linkYesYesYesVista+YesYes (on the same volume)RD folder or Del file

Symbolic links are transparent to users; the links appear as normal NTFS files or directories and can be acted upon by the user or application in exactly the same manner. Symbolic links can span volumes and can use UNC paths.

A symlink can be an absolute path C:\Programs or a path relative to the link’s location \Programs.

Symbolic Links and Directory Junctions are implemented using reparse points.

Hard Links are implemented with multiple file table entries that point to the same inode – the same as Unix hard links. If the original filename is deleted, the hard link will still work – it points directly to the data on disk.

It is possible (but not advisable) to create two links that point to each other in a loop or a link that targets itself. Symbolic links can expose security vulnerabilities in applications that aren’t designed to handle them.

List existing Links and Junctions

The standard DIR command will display Symbolic Links, indicated with <SYMLINKD>
The DIR /A:S command will display Junctions, indicated with <JUNCTION>

DIR /A:S %userprofile%

Elevation

By default, only Administrators can create symbolic links. The security setting ‘Create symbolic links’ can be granted at Configuration\Windows Settings\Security Settings\Local Policies\User Rights Assignment\

Creating a symbolic link requires elevation, but from Windows 10 build 14972, symlinks can be created without needing to elevate the console as administrator – this does however require that you have Developer Mode enabled.

Errorlevels

If the link was successfully created %ERRORLEVEL% = 0
Link could not be created or bad parameters given %ERRORLEVEL% = 1

You may also like...

2 Responses

  1. froleprotrem says:

    You are my inspiration , I possess few blogs and rarely run out from to brand.

  2. zortilonrel says:

    Hello my friend! I wish to say that this post is amazing, nice written and include approximately all significant infos. I would like to see more posts like this.

Leave a Reply

Your email address will not be published. Required fields are marked *