Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to map a UNC path to a local folder on Windows 2003?

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.

like image 472
Davin Studer Avatar asked Dec 02 '10 19:12

Davin Studer


People also ask

How do I map a UNC path?

Launch File Explorer. Select This PC. In the windows that opens, select Computer > Map network drive. Select the drive letter for the network drive you would like to map, enter the UNC path in the Folder text field, then select Finish.

What is the format for the UNC path to a shared folder?

The UNC defines the path to a shared folder using the format \\server\sharename. The server is the computer where the shared folder is stored, and the share name is the name given to the shared folder when the share was set up.

What is the difference between an UNC path and a mapped drive?

A UNC can be accessed without requiring a user logon while a mapped drive can only be accessed by by a logged on user. So a service, or batch, that accesses a remote server should do so with a UNC path and not a drive letter.


2 Answers

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] 
like image 127
Ian Boyd Avatar answered Sep 29 '22 18:09

Ian Boyd


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.

like image 29
ferventcoder Avatar answered Sep 29 '22 18:09

ferventcoder