Symbolic Links in Server 2008/ Vista

This applies to Server 2008 R2 and Windows 7 as well, of course. While this may be old news to some, MaxPC had a good article in their latest issue about using symbolic links in Vista. To paraphrase, symbolic links are like shortcuts but at the OS level, not the file system level. Starting in Vista/Server 2008, Microsoft changed the naming convention for user profile folders which would break applications configured to point to these locations (i.e. c:\documents and settings —> c:\users).  So to preserve application functionality Windows uses symbolic links to provide a path to get to the new location via the old paths, even though they don’t exist anymore. Look inside any user’s profile and you will see what look like shortcuts to my documents, local settings, etc. These are directory symbolic links.

The command mklink is used to create links and its options include: symbolic links for a file or a directory, hard links in place of symbolic links, or directory junctions.   Directory symbolic links probably get the most use and can be useful to preserve pathing of a folder that has been moved to a new location. The original directory name becomes the symbolic link and cannot exist prior to running mklink.

C:\Windows\system32>mklink /D c:\test c:\newtest
Cannot create a file when that file already exists.

C:\Windows\system32>mklink /D c:\test c:\newtest
symbolic link created for c:\test <<===>> c:\newtest

Now any reads or writes looking for c:\test will be seamlessly pointed to c:\newtest and the application won’t know the difference. Hard links are used to point directly to a file so the OS will treat the link like it’s the actual file, while soft links behave more like shortcuts. Links can be deleted directly in the file system just like any other file or folder.

No comments:

Powered by Blogger.