The MKLink tool

To use the MKLink tool, you have to open a command prompt in administrator mode. Here's the easiest way to do so:

  1. Click the Start button.
  2. Type CMD in the Start Search box.
  3. Press and hold down [Ctrl]+[Shift]+[Enter].

A UAC dialog box will appear, and you'll have to respond accordingly.

When the Administrative Command Prompt window appears, just type mklink and you will see the tool's syntax description, as shown in Figure A.

Figure A Figure A

Using the MKLink tool on the command line is easy.

How it works

As an introduction to the MKLink tool, let's take a quick look at how its options work for creating symbolic links.

If you use the base command without any options, you can create a symbolic link to a file. For example, the command:

mklink pad.exe notepad.exe will create a file symbolic link so that typing pad.exe will allow you to launch notepad.exe.

Using the /D option will create a symbolic link to a folder. For example, the command:

mklink /D c:\fruit c:\apples\bananas\oranges

will create a symbolic link called fruit that points directly to the folder oranges.

The /H option will create a hard link rather than a symbolic link. The difference between a hard link and a standard symbolic link is that instead of working like a shortcut, a hard link is more like renaming the file. For example, the command:

mklink /H pad.exe notepad.exe

will make the operating system treat pad.exe as if it were actually notepad.exe.

Finally, the /J option will create a hard link to a folder. This is also called a directory junction (a.k.a. junction point) and instead of working like a shortcut to a folder, a hard link works more like a regular folder. For example, the command:

mklink /J c:\fruit c:\apples\bananas\oranges

will make the operating system work with the long directory structure c:\apples\bananas\oranges just as if it were a single directory named c:\fruit.

If you have been following along and creating any of these types of symbolic links, you can terminate the link simply by deleting it. For instance, to terminate the fruit hard link, you'd simply delete the c:\fruit folder. However, since the link is terminated first and c:\fruit folder is actually empty, you needn't be concerned about data loss in the c:\apples\bananas\oranges folder.