MKLINK – Create and Use Links in Windows

MKLINK – Create and Use Links in Windows

How to Create and Use Links with MKLINK in Windows

   Information
As so many other things in computing, Windows Links seem more complicated to understand and use than what they really are in reality.

This tutorial will tell you how to create and use links using MKLINK to redirect system queries made to a local or network storage location to another location.

In this tutorial we will concentrate on the most important link type, a Directory Junction. A junction is a very practical way to customize your file handling and procedures.


A Link is basically nothing more than a shortcut. Its purpose is to get Windows to think that a file or folder which is physically located in folder Real on drive A is in fact in folder Fake on drive B by creating a link between B:\Fake (a link or junction) and A:\Real (a target folder). Opening the link for instance in Explorer shows contents of target, saving a document to link actually saves it on target.

As Windows now gets a query from user to open B:\Fake this query is sent to A:\Real. In reality the location B:\Fake does not exist but system answers this query as it was a real folder instead of just a symbolic link and presents user the contents of A:\Real as if it was contents of B:\Fake. Sounds complicated? Don’t worry, it’s quite easy in fact.



Part 1: What is a Link?

   Note
A Link in Windows is a virtual object that points to a real physical location. It can be compared to Windows desktop shortcut, doing essentially the same thing in redirecting user to a physical storage location.


A Link can be so called Hard Link linking one file to a target file, or a Soft Link linking a folder to a target folder. Soft Links are also called Symbolic Links. Third link type is Junction, basically a hard link but as hard links can only link files we need to use junctions to link folders.

If you are using Windows Vista or later you have most probably used links without ever noticing it. In Windows XP all user data was saved in a folder called C:\Documents and Settings (default name and location). Windows Vista changed this; instead of Documents and Settings the data was divided between two system folders, C:\Users for user specific application data and personal files and folders, and C:\ProgramData for all users shared application data. To allow backwards compatibility all Windows versions since Vista have a link C:\Documents and Settings with two target folders, ProgramData and Users.

You can check this by yourself by allowing protected system files and folders to be shown and opening C: drive on Explorer:
mklink_01.png
(Please notice, screenshots from Windows 8 but links work the same way on Windows 7. Highlighted with yellow = visible system folders created by Windows installation, red = hidden or protected system folders.)

If you try to open Documents and Settings you get an "Access Denied" message. It does not exist, there is no such folder on your C: drive but it is needed for legacy software.

An example: You want to install Microsoft Office XP on your Windows 7. As Office XP was published for Windows XP long before Vista it uses the XP system folder Documents and Settings to store user data. Vista and later Windows do no longer have this folder so a link is needed. Office XP setup thinks it is creating files and folders normally in Documents and Settings but actually your Windows 7 is lying ;) to Office XP setup, not telling it those files and folders are in fact created in Users and ProgramData. Office XP setup does not notice this deception, installation works and later when user works with Office XP it still thinks the Documents and Settings folder is there, never learning the fact that all queries to that folder are sent further and returned as if they really came from Documents and Settings.



Part 2: Working with Directory Junctions

(1.) Command Syntax

Links are created wit command mklink, short from Make Link. Typing mklink /? on Command Prompt you get the command syntax and options:
Code:
[B]MKLINK [/B][[/D] | [/H] | [/J]] [B]Link [/B][B]Target[/B]
 
        [B]/D[/B]      Creates a directory symbolic link.  Default is a file symbolic link.
       [B]/H[/B]      Creates a hard link instead of a symbolic link.
        [B]/J [/B]  Creates a Directory Junction.
        [B]Link    [/B]specifies the new symbolic link name.
        [B]Target  [/B]specifies the path (relative or absolute) that the new link refers to.

(2.) Use an Elevated Command Prompt

You must use elevated command prompt to work with links.

(3.) Create a Link or a Junction

Creating a directory junction D:\Docs with target E:\Users\Kari\Documents:
Code:
mklink /j D:\Docs E:\Users\Kari\Documents
Windows tells you clearly if the creating of junction has succeeded:
mklink_02.png
(4.) Main principles when creating a link or a junction

  1. A file or a folder with the name of the intended Link name may not exist. The link file or folder name must be free to use, not reserved by an existing file or folder. If the name is reserved you get an error message. My D: drive already has a folder Test, this is what happens when trying to create a junction with D:\Test (already an existing folder) as link and E:\Users as target:
    mklink_03.png
    Notice that command prompt is telling about a file already existing instead of a folder. This is because the system sees links as shortcuts (files) and not as folders.
  2. Target folder may but must not exist. If it does not exist at the time when a link is created it must be created before you can use the link:
    mklink_04.png
  3. Target can be another Link. Above in (3.) we created a junction D:\Docs with target E:\Users\Kari\Documents. Following command would now create a link C:\Docs with target D:\Docs:
    Code:
    mklink /j C:\Docs D:\Docs
    In fact Windows sees no difference if the target is a real physical folder location or just another link. In this case all queries to C:\Docs would be sent to D:\Docs which would send them further to E:\Users\Kari\Documents. If a user now opens C:\Docs in Explorer, it shows the contents of E:\Users\Kari\Documents:
    mklink_05.png
    Noticed something interesting in screenshot above? The target folder is called Documents but Explorer shows it as My Documents. This is because those "My ..." folders in your user profile folder are actually not real folders. They are directory links: My Videos is simply a link with target Videos and so on.
(5.) Remove or rename a link

Links and junctions can be renamed and removed as any real folders. System automatically modifies registry and sets the target to be the same for a renamed link as it was on the original link.

This is because even not really existing, the system handles links as if they were real existing folders. This is what Explorer shows when asked for Properties for our example junction D:\Docs:
mklink_07.png
Only way to really see it is in fact a junction is to get directory listing in command prompt:
mklink_06.png
The listing not only shows it is a junction but also its target folder.


Part 3: Practical Examples

A typical situation: You have bought a game that must be installed on root level folder C:\Games. Your C: drive is becoming full, so you decide to move the whole C:\Games folder to D:, delete now empty C:\Games (remember, link folder may not exist) and create a junction:
Code:
mklink /j C:\Games D:\Games
When launching the game it still assumes it is located on C: although you, me and Windows know better ;): it's "secretly" residing on D: but still using the old address on C:.

Another situation: You want to work with some pics from last Christmas, to edit them to be ready to be published on that website of yours. Pics are currently located in X:\Backups\Pictures\My Pictures\Holidays\Christmas 2012.

You can create a junction X:\Pics, and now whenever you want to work with those pics you just type X:\Pics to Run dialog to open the correct folder:
Code:
mklink /j X:\Pics "X:\Backups\Pictures\My Pictures\Holidays\Christmas 2012"
Notice that if a path contains spaces it must be set in between quotation marks as in above target path.

That's about it. Any feedback welcome.

Kari
 
Last edited:
Great tutorial Kari. :)
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self built custom
OS
64-bit Windows 11 Pro for Workstations
CPU
Intel i7-8700K OC'd to 5 GHz
Motherboard
ASUS ROG Maximus XI Formula Z390
Memory
64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz
Graphics Card(s)
ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
Sound Card
Integrated
Monitor(s) Displays
2 x Samsung Odyssey G7 27"
Screen Resolution
2560x1440
Hard Drives
1TB Samsung 990 PRO M.2,
4TB Samsung 990 PRO PRO M.2,
TerraMaster F8 SSD Plus NAS
PSU
Seasonic Prime Titanium 850W
Case
Thermaltake Core P3
Cooling
Corsair Hydro H115i
Keyboard
Logitech wireless K800
Mouse
Logitech MX Master 4
Internet Speed
2 Gb/s Download and 100 Mb/s Upload
Antivirus
Malwarebyte Anti-Malware Premium
Browser
Google Chrome
Other Info
Logitech Z625 speaker system,
Logitech BRIO 4K Pro webcam,
HP Color LaserJet Pro MFP M477fdn,
APC SMART-UPS RT 1000 XL - SURT1000XLI,
Galaxy S23 Plus phone
Nice tutorial Kari. If you don't feel comfortable with command prompt there is a GUI for it. Junction Link Magic
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Hewlett-Packard/G62-107SA Notebook
OS
Microsoft Windows 7 Home Premium 64-bit Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 330 @ 2.13GHz
Motherboard
Hewlett-Packard 1425
Memory
8 GB DDR3
Graphics Card(s)
Intel(R) HD Graphics
Sound Card
Realtek High Definition Audio
Monitor(s) Displays
Builtin
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
250 GB SATA Hard Disk Drive 7200 rpm
2TB Seagate GoFlex USB 2 Drive
1TB Iomega Prestige USB 2 Drive
1.5TB Iomega Prestige USB 2 Drive (Samsung)
2TB WD MyBook Live NAS.
Mouse
Logitech Anywhere MX
Internet Speed
152 Mbs download 10 Mbs upload
Antivirus
Norton 360
Browser
Chrome
Thanks geeks!

Never used that GUI for junctions, Kado but it could be practical for those not familiar with Command Prompt. For me the CP is perfect to play with when nostalgic feelings hit me and I need to remember those good old days when we had to walk 10 miles in heavy rain carrying our younger siblings just to get a file copied from C: to D: ;).
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP ENVY 17-1150eg
OS
Windows 10 Pro x64 EN-GB
CPU
1.6 GHz Intel Core i7-720QM Processor
Memory
6 GB
Graphics Card(s)
ATI Mobility Radeon HD 5850 Graphics
Sound Card
Beats sound system with integrated subwoofer
Monitor(s) Displays
17" laptop display, 22" LED and 32" Full HD TV through HDMI
Screen Resolution
1600*900 (1), 1920*1080 (2&3)
Hard Drives
Internal: 2 x 500 GB SATA Hard Disk Drive 7200 rpm
External: 2TB for backups, 3TB USB3 network drive for media
Cooling
As Envy runs a bit warm, I have it on a Cooler Master pad
Keyboard
Logitech diNovo Media Desktop Laser (bluetooth)
Mouse
Logitech Performance Mouse MX
Internet Speed
50/10 Mbps VDSL
Antivirus
Windows Defender 4.3.9431.0
Browser
Maxthon 3.5.2., IE11
Thanks Kari, I created a link and would like to delete it I am still not sure of the proper path can you help
I created mklink/j C:\Users\Brett M:\Users\Brett
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 7 Pro 64 bit
CPU
AMD FX
Hi Motigerman, welcome to the Seven Forums.

You delete junctions as you would delete folders. In command prompt, the syntax is:
Code:
rd C:\Folder\Subfolder
Above example would delete the folder or junction called Subfolder which is located in C:\Folder. The command rd comes from words Remove Directory (directory = folder).

Kari
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP ENVY 17-1150eg
OS
Windows 10 Pro x64 EN-GB
CPU
1.6 GHz Intel Core i7-720QM Processor
Memory
6 GB
Graphics Card(s)
ATI Mobility Radeon HD 5850 Graphics
Sound Card
Beats sound system with integrated subwoofer
Monitor(s) Displays
17" laptop display, 22" LED and 32" Full HD TV through HDMI
Screen Resolution
1600*900 (1), 1920*1080 (2&3)
Hard Drives
Internal: 2 x 500 GB SATA Hard Disk Drive 7200 rpm
External: 2TB for backups, 3TB USB3 network drive for media
Cooling
As Envy runs a bit warm, I have it on a Cooler Master pad
Keyboard
Logitech diNovo Media Desktop Laser (bluetooth)
Mouse
Logitech Performance Mouse MX
Internet Speed
50/10 Mbps VDSL
Antivirus
Windows Defender 4.3.9431.0
Browser
Maxthon 3.5.2., IE11
Access denied

Hello all,
I have a windows 7 Professional 64 bit and I want to make symbolic link to a known network on the folder that I have full access permission. The Network computer is windows server 2000. I mapped the folder that I have full access to my windows 7 with H: which redirect me to windows 2000 server where I have full access.

As u know the typical usage of Mlink is (Mklink /D LINK TARGET)

If I use this kind of symbol link where the LINK is on the server that I described I get access denied :

mklink \D h:\test c:\test ( Access Denied)

However; I have no errors if I change the LOCAL and TARGET arguments

mklink \D c:\test h:\test ( successfully done)


It should be something belong to the permission policy as it should make the folder test on (h:) if I use the first alternative. But I have full permission on that folder.
Anyone has any idea why I have access denied?

Thx
 

My Computer

Computer type
PC/Desktop
OS
windows 7 professional 64 bits
Using mklink for networked drives

Hi Kari,

Thanks for the useful post on using mklink. How do you use mklink to make links to a network drive?
i.e. a drive that doesn't show up as a X:

Thanks

Axle
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
lenovo
OS
Win 7 32bit
CPU
?
Motherboard
?
Memory
4GB
Graphics Card(s)
?
Hard Drives
400GB
Antivirus
AVG
Browser
Chrome
First:
sam80, I am really sorry I noticed your post first half a year after it was posted here. I have no explanations, I do not know how the hell I have not noticed it before :o.

Your question: both link and target must be on local volumes. Creating a link on a network drive will not work.


AxledeMaxle, simple answer is you can't. Both link and target must be on local volumes. See this screenshot and explanations below it:

2014-02-10_09h36_00.png

  1. Trying to "fool" MKLINK to think a network drive is in fact a local volume, I assign drive letter Z: to network folder \\Computer_Name\Folderpath using my credentials on that network computer
  2. Testing it with command DIR Z: I can see the drive is correctly mapped and shown in my local computer
  3. Using MKLINK I try to create a link D:\Docs on local computer, target Z:\Documents which in reality is a network folder \\AGM-SERVER\Users\Public\Documents. MKLINK cannot create the link telling Local volumes are required to complete the operation
  4. Another try with MKLINK, this time using the network path for target. The same error than in 3.
Kari
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP ENVY 17-1150eg
OS
Windows 10 Pro x64 EN-GB
CPU
1.6 GHz Intel Core i7-720QM Processor
Memory
6 GB
Graphics Card(s)
ATI Mobility Radeon HD 5850 Graphics
Sound Card
Beats sound system with integrated subwoofer
Monitor(s) Displays
17" laptop display, 22" LED and 32" Full HD TV through HDMI
Screen Resolution
1600*900 (1), 1920*1080 (2&3)
Hard Drives
Internal: 2 x 500 GB SATA Hard Disk Drive 7200 rpm
External: 2TB for backups, 3TB USB3 network drive for media
Cooling
As Envy runs a bit warm, I have it on a Cooler Master pad
Keyboard
Logitech diNovo Media Desktop Laser (bluetooth)
Mouse
Logitech Performance Mouse MX
Internet Speed
50/10 Mbps VDSL
Antivirus
Windows Defender 4.3.9431.0
Browser
Maxthon 3.5.2., IE11
Try /d option

Hi! I was able to get network shares to link using the /d option - to a drive letter and to a UNC path. Hope this helps!
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Enterprise x64
That's good to know, thanks for sharing.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP ENVY 17-1150eg
OS
Windows 10 Pro x64 EN-GB
CPU
1.6 GHz Intel Core i7-720QM Processor
Memory
6 GB
Graphics Card(s)
ATI Mobility Radeon HD 5850 Graphics
Sound Card
Beats sound system with integrated subwoofer
Monitor(s) Displays
17" laptop display, 22" LED and 32" Full HD TV through HDMI
Screen Resolution
1600*900 (1), 1920*1080 (2&3)
Hard Drives
Internal: 2 x 500 GB SATA Hard Disk Drive 7200 rpm
External: 2TB for backups, 3TB USB3 network drive for media
Cooling
As Envy runs a bit warm, I have it on a Cooler Master pad
Keyboard
Logitech diNovo Media Desktop Laser (bluetooth)
Mouse
Logitech Performance Mouse MX
Internet Speed
50/10 Mbps VDSL
Antivirus
Windows Defender 4.3.9431.0
Browser
Maxthon 3.5.2., IE11
No Problem! I believe it only applies to Vista and above. Nicely documented write-up, that was the refresher I needed to get things done.
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Enterprise x64
does this command work for files?

i try this:
D:\Users\Desktop>mklink /h ..\Documents\link.pdf original_file.pdf

it works.. i did a dir/w to confirm it is not using disk space.. and when i copy to another drive.. it copy like normal file.

but am i doing it correct?
 

My Computer

Computer type
PC/Desktop
OS
Win7 x64
Hi Absoluthk, welcome to the Seven Forums.

MKLINK command does not physically move the file or folder. Your original_file.pdf stays where it was, the link created in Documents\link.pdf is just a link, kind of shortcut.

Kari
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP ENVY 17-1150eg
OS
Windows 10 Pro x64 EN-GB
CPU
1.6 GHz Intel Core i7-720QM Processor
Memory
6 GB
Graphics Card(s)
ATI Mobility Radeon HD 5850 Graphics
Sound Card
Beats sound system with integrated subwoofer
Monitor(s) Displays
17" laptop display, 22" LED and 32" Full HD TV through HDMI
Screen Resolution
1600*900 (1), 1920*1080 (2&3)
Hard Drives
Internal: 2 x 500 GB SATA Hard Disk Drive 7200 rpm
External: 2TB for backups, 3TB USB3 network drive for media
Cooling
As Envy runs a bit warm, I have it on a Cooler Master pad
Keyboard
Logitech diNovo Media Desktop Laser (bluetooth)
Mouse
Logitech Performance Mouse MX
Internet Speed
50/10 Mbps VDSL
Antivirus
Windows Defender 4.3.9431.0
Browser
Maxthon 3.5.2., IE11
MKLINK is an old DOS command. It works on DOS and Windows Command Prompt.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP ENVY 17-1150eg
OS
Windows 10 Pro x64 EN-GB
CPU
1.6 GHz Intel Core i7-720QM Processor
Memory
6 GB
Graphics Card(s)
ATI Mobility Radeon HD 5850 Graphics
Sound Card
Beats sound system with integrated subwoofer
Monitor(s) Displays
17" laptop display, 22" LED and 32" Full HD TV through HDMI
Screen Resolution
1600*900 (1), 1920*1080 (2&3)
Hard Drives
Internal: 2 x 500 GB SATA Hard Disk Drive 7200 rpm
External: 2TB for backups, 3TB USB3 network drive for media
Cooling
As Envy runs a bit warm, I have it on a Cooler Master pad
Keyboard
Logitech diNovo Media Desktop Laser (bluetooth)
Mouse
Logitech Performance Mouse MX
Internet Speed
50/10 Mbps VDSL
Antivirus
Windows Defender 4.3.9431.0
Browser
Maxthon 3.5.2., IE11
Yes! That /d option is a real winner. But does it have limitations? I need to know if there is a limit on the number of clients trying to access files located at a symbolic directory link created by the /d option. Thanks in advance for any help you could provide.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell Precision T3600
OS
Windows 7 Ultimate x64
CPU
12-core Xeon 3.2 GHz
Memory
16 GB
Trying to post a reply, but no refresh!

Yesterday I posted a reply, but it did not persist in this blog. But today, when I post a reply, yesterdays post shows up. At least it did the first time. :confused:
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell Precision T3600
OS
Windows 7 Ultimate x64
CPU
12-core Xeon 3.2 GHz
Memory
16 GB
Phantom blog entry found

Yesterday I posted a reply, but it did not persist in this blog. But today, when I post a reply, yesterdays post shows up. At least it did the first time. :confused:

Okay! This tutorial takes up two pages - and I'm on page 2!
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell Precision T3600
OS
Windows 7 Ultimate x64
CPU
12-core Xeon 3.2 GHz
Memory
16 GB
When to use mklink /D

Very useful guide, but I'm still unclear about when and why to use default file flag or /D directory flags. -
 

My Computer

Computer type
Tablet
Computer Manufacturer/Model Number
Samsung Series 7 Slate XE700T1A
OS
Windows 8.1 Ult x64 & Windows 7 x32
Back
Top