Symbolic link in Windows Vista


You can create symbolic link in Windows Vista now.


C:\test>ver


Microsoft Windows [Version 6.0.5365]


C:\test>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.


C:\test>mklink foo c:\Windows\system32\notepad.exe
symbolic link created for foo <<===>> c:\Windows\system32\notepad.exe


C:\test>dir
 Volume in drive C has no label.
 Volume Serial Number is 2211-7428


 Directory of C:\test


04/14/2006  11:24 AM    <DIR>          .
04/14/2006  11:24 AM    <DIR>          ..
04/14/2006  11:24 AM    <SYMLINK>      foo [c:\Windows\system32\notepad.exe]
               1 File(s)              0 bytes
               2 Dir(s)  69,238,722,560 bytes free


C:\test>mklink /d bar c:\windows
symbolic link created for bar <<===>> c:\windows


C:\test>dir
 Volume in drive C has no label.
 Volume Serial Number is 2211-7428


 Directory of C:\test


04/14/2006  11:24 AM    <DIR>          .
04/14/2006  11:24 AM    <DIR>          ..
04/14/2006  11:24 AM    <SYMLINKD>     bar [c:\windows]
04/14/2006  11:24 AM    <SYMLINK>      foo [c:\Windows\system32\notepad.exe]
               1 File(s)              0 bytes
               3 Dir(s)  69,238,722,560 bytes free


C:\test>del foo


C:\test>dir
 Volume in drive C has no label.
 Volume Serial Number is 2211-7428


 Directory of C:\test


04/14/2006  11:24 AM    <DIR>          .
04/14/2006  11:24 AM    <DIR>          ..
04/14/2006  11:24 AM    <SYMLINKD>     bar [c:\windows]
               0 File(s)              0 bytes
               3 Dir(s)  69,238,722,560 bytes free


C:\test>rd bar


C:\test>dir
 Volume in drive C has no label.
 Volume Serial Number is 2211-7428


 Directory of C:\test


04/14/2006  11:24 AM    <DIR>          .
04/14/2006  11:24 AM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  69,238,722,560 bytes free


(By default only administrators can create symbolic link. You can override the decision using secpol.msc.)


Documentation of symbolic link can be found in MSDN


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/symbolic_links.asp

Comments (26)

  1. Mike says:

    Why admin only by default?

  2. Uwe Keim says:

    Really great news!

  3. macbirdie says:

    It’s the same as creating junctions in any other NTFS 5.0 volume with sysinternals or Win 2003 resource kit tools, isn’t it?

  4. macbirdie says:

    Err, ok, on second thought – it must be a hybrid of some kind since the junctions work only for directories. Sorry for the fuss. 😉

  5. How is this different than hardlinks in XP.

    fsutil

    Can it span volumes?

  6. junfeng says:

    It is the same as hardlink vs symlink in Unix.

    I believe it can span volumes, as I can create a symlink to an UNC path.

  7. Norman Diamond says:

    > /D Creates a directory symbolic link.

    > Default is a file symbolic link.

    Why doesn’t the default depend on the kind of object being linked to?

    What happens if the person creates a directory symbolic link to a file, or a file symbolic link to a directory?

    And I wonder the same thing as Mike.  If you don’t let ordinary users create links in their directories under Documents and Settings or Users because the links might point to WindowsSystem32, well then, ordinary users will still have to type WindowsSystem32 at the command line.  This inconveniences them but doesn’t add security.

  8. junfeng says:

    Norman,

    Again, I don’t work in File System team so I can’t answer any of your questions.

  9. Martin v. Löwis says:

    Looking at the documentation, it is unclear how to determine (programmatically) that a directory entry is a symbolic link, and there seems to be no API to get the contents (i.e. target path name) of the link.

  10. jsminch says:

    This is great.  I love the symbolic link idea.  

    I did not see anywhere in your example or in the MS doc wheather or not deleting the link deletes the object that it links to (a weakness of "junction points").  But I will assume that it does not (hopefully you didn’t delete your windows directory), so, groovy.

    I hope they work it into the GUI.

  11. re: Windows Vista 体験記 – mklink

  12. A new but low-level addition to Vista is the support for symbolic links in the file system. These are…

  13. Dennes says:

    Depois de pesquisar acabei descobrindo que as JUNCTIONS existem no sistema operacional desde…

  14. Chris Eargle says:

    Columbia Enterprise Developers Guild Begins

  15. Shadowin says:

    A couple of months ago, I began searching for local developer user groups to take part in Columbia, SC. Unfortunately, there didn&rsquo;t seem to be a lot going on. I ended up heading to the Charlotte Enterprise Developers Guild to get my fix. There,