Using Symlinks in Windows Vista
One of the long-awaited features in Windows Vista was the ability to use symbolic links, the way you can in linux. Sadly, they don't work quite as well as they could, but it's a big upgrade from prior versions, and has solved a number of problems for me already.
Using the mklink Command
The command that you need to use is mklink, which you'll use from the command line. Just type it on the command line to see the options:
C:Usersgeek>mklink
Creates a symbolic link.
MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to.
For instance, if you wanted to make the folder C:\Users\Geek\TestFolder available from C:\TestFolder as well, you could use the following command.
C:\mklink /D C:\TestFolder C:\Users\Geek\TestFolder
symbolic link created for C:\TestFolder <<===>> C:\Users\Geek\TestFolder
Now if you look in C:\TestFolder directory, you'll see whatever files were in the other directory.
Understanding the Options.
MKLINK link target
Using the command without any extra options creates a soft link to a file.
/D creates a symbolic link, or a soft link.
This essentially acts like a shortcut to a folder in prior versions of Windows, except you don't have to use an actual shortcut.
/H creates a hard link, which points directly to the file.
This option can't be used for folders directly for some reason, you'll have to use the next option.
/J creates a "Directory Junction"
A Directory Junction is actually just a hard link to a directory. This is a feature that existed prior to Vista as well. If you are trying to symlink to a directory using a hard link, then you should use this option.
Understanding Hard vs Soft Links
Hard Link
A hard link directly points to the file, and acts to the operating system as if it is the file itself. You'll want to use this option the majority of the time if you are trying to fake an application's directory.
Soft Link
A soft link is essentially a shortcut to a file or folder - if you are using Windows explorer, you'll be redirected to the directory if you double-click on a shortcut, it won't pretend its part of the filesystem. You can still directly reference or open a file with the symlinked path, and it mostly works.
Using Symlinks from a Network Share
One of the things that's been extensively discussed is that you cannot use the Vista symlinks from another operating system (not surprising), but you cannot use them from a network share either. This is troublesome if you expect to use this feature on a web server or a file server.
Deleting Symlinks
To delete a symlink, you can just delete the link. Just make sure you don't delete the original file.


Excellent post, that really laid it out for me. I figured the gist of what they were, but didn't fully appreciate the differences. Thanks.
Good post, but I have something to add to network shares: with Windows Longhorn Server you will be able to create link to network shares.
Cheers
Alexandre
Alexandre,
That's very interesting, I hadn't heard that. I'm going to have to look into that more.
Ya, but System Restore will NOT work properly. Temporary user accounts appear, and all user settings seem to be lost. Argh!
To be a bit more correct:
* shortcut: on the operating system level (to applications who wish to read/write the link, it's just a meaningless file)
* soft link (or symbolic link): like a shortcut, but on the filesystem level (applications reading/writing the link, will actually read/write the file linked to)
-> unfortunately this only works with folders on Windows, not with files (which is the reason I'm searching around for information at the moment, I need file symlinks, like in *nix.)
-> this will work across partitions, or drives
* hard link: only for files, what happens is that there are multiple file entries that point to the same physical data, when you delete one entry, the other will still work, the data won't be gone until all entries are deleted (if with a soft link you delete the original directory, the link won't work anymore!)
-> you can obviously only create hard links to a file on the same partition
I recommend this app: http://schinagl.priv.at/nt/har.....llext.html
Easy Drag and Drop creation of hard links, symbolic links, etc for Vista and XP.
Concept nicely explained and simplified. Thanks.
And now for a good laugh: try creating a link, within a folder, to itself, as in…
1. We have a folder called C:\TestFolder
2. Within TestFolder, we create a link:
mklink /D myself C:\TestFolder
3. We now click on the new link and start laughing…. or crying ( your choice! )
I just wonder: Should it be considered a bug ?
Could this be used to 'move' the C:\Users folder to D:\Users (or another drive) by making C:\Users a hard link to D:\Users ???
I'm thinking that C:\Users would still exist but would link to and store files in D:\Users
And 'safer' then the rather messy registry hack (which I've heard has some issues and limitations)
Yes Steve, you can do that. Actually Vista does something very similar when it installs to give legacy applications a psuedo Pre-Vista environment. Open a command prompt and cd to the root. Type dir. You'll see Users as expected, but notice that Documents and Settings is no where to be found. Try to cd to Docu[tab]… it comes right up. Press ESC and now type dir /a. You'll see that Documents and Settings has been made into a Junction. Try exploring your User directory, you'll be surprised at how many places Microsoft has used Junctions and how few people know.
Hi, I did not get the point about using Hardlinks on network shares.
What I just tried:
1) created a network share BACKUP1 on E:\BACKUP1 (on vista)
2) cmd > e: > cd backup1 > mklink /J TEST1 W:\Music (on vista)
3) used mount -t smbfs **someoptions** //192.168.2.2/BACKUP1 /tmp/testsmb on my linux box
4) cd /tmp/testsmb/TEST1/**somedeeperstructure**/ (on linux box)
5) less a.txt (on linux box)
Result: worx perfectly.
BTW: no SP1 applied to Vista.
Cheers, Frank
I'm having an error with this:
'C:\mklink' is not recognized as an internal or external command, operable program or batch file.
Running Vista Ultimate with SP1.
Any help?