29

I know that I can map a UNC path to a local drive letter. However, I am wondering if there is a way to map a UNC path to a local folder. I have a program that has a specific folder hard coded into the program and I am wanting to try and create a folder with the same name that is mapped to a UNC path so that the data can be accessed from a network share. Is this doable? Specifically this is on a Windows 2003 server.

7 Answers 7

24

Yes, there is a way to map a UNC path to a local folder:

C:\>mklink /D Develop \\obsidian\Develop
symbolic link created for Develop <<===>> \\obsidian\Develop

This is because i want a build server to use my own PC's Develop folder as its Develop folder:

10/20/2012  11:01 AM    <SYMLINKD>     Develop [\\obsidian\Develop]

And there you have it.


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.

Note: In my actual situation i needed another level of redirection, because the program i'm using realized that Develop was a symbolic link, pointing to a remote machine, and refused to comply. i told the program to shut up and do what it's told by giving it a junction that points to a local resource.

10/20/2012  11:06 AM    <JUNCTION>     Develop [C:\Develop2\]
10/20/2012  11:01 AM    <SYMLINKD>     Develop2 [\\obsidian\Develop]
5
  • 3
    Did you check to ensure the appropriate settings were enabled for symlink evaluation: fsutil behavior query SymlinkEvaluation You might just need to enable some of them depending on the configuration of your symlinks. E.g. fsutil behavior set SymlinkEvaluation R2R:1. This got my .net program to comply.
    – grasmi
    Apr 29, 2013 at 15:01
  • 3
    This does NOT work on Windows 2003 like the OP asked for. Added an answer to make it look like MkLink is installed on Windows 2003 and provides symlink behavior for UNC on 2003: stackoverflow.com/a/18593425/18475 Sep 3, 2013 at 13:21
  • 1
    The note did work for a custom application I use. My understanding is the the OS layer handle the conversion of the symlink for the application and so this make it seamless for the end users.
    – LMA1980
    Dec 18, 2014 at 18:18
  • 2
    The extra redirection is genius! This was the magic that solved my problem (trying to get gulp/bower working for a VS project using UNC paths - due to running Windows inside Parallels on a Mac).
    – John
    Jul 24, 2015 at 18:45
  • grasmi's comment worked for my purposes. by enabling remote to remote I can essentially treat the link the same way that I can as a local resource Aug 8, 2016 at 17:14
16

This meets exactly what the OP asked for - a symbolic link for Windows 2003 that maps to a network share. After many hours looking at others and testing them, this is the only component I found that will work with network shares.

Symbolic Link Driver for Windows XP

This utility will work for both XP and 2003 mapping to a network share and creating a symlink: http://schinagl.priv.at/nt/ln/ln.html#symboliclinksforwindowsxp

Now put this in a directory that you put on the path and you have the ability to create symlinks using senable.exe (with symlink.sys) and ln.exe (you will need that from the above site as well along with its dependency on the Visual C++ runtime DLLs).

Added Bonus: Fake out MkLink

Put these additional two files into the same directory where you have senable.exe and make sure this is all on the path.

mklink.cmd:

@echo off

SET DIR=%~dp0%
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%Symlink.ps1' %*"

pushd "%DIR%"
"%DIR%senable.exe" start
popd

Symlink.ps1:

param (
 [string]$symlinktype,
 [string]$link,
 [string]$target
)

$scriptpath = $MyInvocation.MyCommand.Path
$ScriptDir = Split-Path $scriptpath

$senable = Join-Path "$ScriptDir" senable.exe
$ln = Join-Path "$ScriptDir" ln.exe

pushd "$ScriptDir"
& cmd /c "$senable" install
popd
& cmd /c "$ln" -s "$target" "$link"

Note:

You need the following other items installed on Windows 2003 (non-R2, I'm not fully sure what you need for R2 yet):

  • Microsoft .NET Framework 2.0 Service Pack 1
  • Windows Imaging Component
  • Windows Server 2003 Service Pack 2
  • Windows Management Framework Core (this brings PowerShell 2)

Chocolatey Package

I created a chocolatey package that will do all of this for you: http://chocolatey.org/packages/win2003-mklink

Important Note

Unlike regular symlinks, you can not simply delete the folder to remove the symbolic link folder. If you do that, it will delete the real folder it it pointing to. So use with extreme care.

4
  • 2
    Thanks, that worked for me on Windows XP. Basically, as documentation says, one needs to install driver (senable.exe install) and symlink the path (ln -s //host/share/folder name).
    – dma_k
    Jan 21, 2014 at 17:28
  • @ferventcoder Sadly, ln.exe seems to have a rather restrictive license, which prohibits redistribution. schinagl.priv.at/nt/ln/license.txt
    – dabide
    Jul 22, 2014 at 14:39
  • Great, looks like I'll need to download it during the install instead. :( Jul 24, 2014 at 15:21
  • I just fixed this to come to terms of the license (download from official distribution during package install). @dabide Jul 24, 2014 at 16:39
5

You can't do it directly, but if you create a symbolic link you should be able to point it at the Mapped drive letter.

net use e: \\\\shares\folder # You will want to set this up persistent or next reboot will break it.

Browse using cmd to your location you want the link:

cd c:\folder

mklink /d name e:\

Now anything that accesses c:\folder\name\ will be accessing \\\\shares\folder\

1
  • 3
    With this approach you will need to consider the context under which the application will ultimately be running. Mapped drives can vary from user to user, and may not be available to service accounts depending on your environment.
    – grasmi
    Apr 29, 2013 at 14:31
2

According to Microsoft YOU CAN NOT map a shared folder on a remote machine (server) to a local folder.

For example, this will not work:

  • shared folder on Server: \\\Server\share1
  • mapped share on a local machine: c:\MyProgram\Some_Useful_Files_Here

As Microsoft stated, you CAN NOT do mklink on a remote machine; at least not for Junction or Hard-links. You can ONLY do it as a Symbolic link, which is basically a shortcut.

So if a certain program needs access to a local folder which is the same as on the server, sorry no luck! Windows is not Linux, let's not forget that :-(

1
  • So, what's wrong with using a symbolic link? Those let you use paths as if the location existed. "mklink /d .." works fine for remote, according to threads elsewhere. (Server 2008+ or Vista+) Mar 20, 2014 at 21:19
1

You cannot map it directly, no. You could try implementing a Shell Namespace Extension that is registered as part of the file system so you can root it where you need, and then have it access the UNC path internally. Not a trivial thing to implement, but it should give you the end result you are looking for.

0

After much trying I finally figured out that you cannot do it the way I wanted to. I tried a symbolic link using the mklink functionality in Server 2008, but it turns out that the .NET System.IO api does not recognize symbolic links.

So, if you do a Directory.GetFiles() on a folder that is symbolically linked it will throw an error.

3
  • 2
    Did you check to ensure the appropriate settings were enabled for symlink evaluation: fsutil behavior query SymlinkEvaluation You might just need to enable some of them depending on the configuration of your symlinks. E.g. fsutil behavior set SymlinkEvaluation R2R:1
    – grasmi
    Apr 29, 2013 at 14:57
  • 1
    This is false - take a look at my answer stackoverflow.com/a/18593425/18475 Sep 16, 2013 at 17:36
  • 2
    FYI, System.IO.Directory.GetFiles("C:\Whatever\MySymbolicLink") in .Net 3.5 on my Win 7 64-bit works fine with symbolic link created using "mklink /d C:\Whatever\MySymbolicLink some-target-path". Mar 20, 2014 at 21:23
0

Assuming you want to map \\moo\cow to C:\cow_files, and that there is not already a server called moo (if there was you could just share the folder directly, so I assume there isn't), you could:

  1. Edit the hosts file (or your actual DNS if you can) to map moo to the machine with C:\cow_files on it. (Or to localhost if the directory is local to the client that needs the mapping.)

  2. Share C:\cow_files as cow on that machine.

You should then be able to map to \\moo\cow and get the files you need, unless I've missed something (which is possible :)).

1
  • 3
    Useful suggestions, however the OP is attempting to do the OPPOSITE: He has apps that ASK FOR "C:\cow_files", and wants that app to still work, even though the files now live on \\moo\cow. So he needs a symbolic link "mklink \d C:\cow_files \\moo\cow", not the other way around (which wouldn't be possible thru mklink, so something like you suggest would be useful in that other case). Really, the only challenge he's having is that he's on an older system, so "mklink" isn't available to him. Mar 20, 2014 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.