有没有办法将 UNC 路径映射到 Windows 2003 上的本地文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4339220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to map a UNC path to a local folder on Windows 2003?
提问by Davin Studer
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.
我知道我可以将 UNC 路径映射到本地驱动器号。但是,我想知道是否有办法将 UNC 路径映射到本地文件夹。我有一个程序,它有一个硬编码到程序中的特定文件夹,我想尝试创建一个映射到 UNC 路径的同名文件夹,以便可以从网络共享访问数据。这是可行的吗?具体来说,这是在 Windows 2003 服务器上。
采纳答案by ferventcoder
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.
这完全符合 OP 的要求 - 映射到网络共享的 Windows 2003 符号链接。经过数小时的查看和测试,这是我发现的唯一可以与网络共享一起使用的组件。
Symbolic Link Driver for Windows XP
用于 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
此实用程序适用于 XP 和 2003 映射到网络共享并创建符号链接: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).
现在把它放在一个你放在路径上的目录中,你就可以使用senable.exe
(with symlink.sys
) and ln.exe
(你将需要来自上面的站点以及它对 Visual C++ 运行时 DLL 的依赖)创建符号链接。
Added Bonus: Fake out MkLink
额外奖励:伪造 MkLink
Put these additional two files into the same directory where you have senable.exe
and make sure this is all on the path.
将这两个额外的文件放入您所在的同一目录中,senable.exe
并确保它们都在路径上。
mklink.cmd:
mklink.cmd:
@echo off
SET DIR=%~dp0%
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%Symlink.ps1' %*"
pushd "%DIR%"
"%DIR%senable.exe" start
popd
Symlink.ps1:
符号链接.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):
您需要在 Windows 2003 上安装以下其他项目(非 R2,我还不能完全确定 R2 需要什么):
- 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)
- Microsoft .NET Framework 2.0 服务包 1
- Windows 映像组件
- Windows Server 2003 服务包 2
- Windows 管理框架核心(这带来了 PowerShell 2)
Chocolatey Package
巧克力包装
I created a chocolatey package that will do all of this for you: http://chocolatey.org/packages/win2003-mklink
我创建了一个巧克力包,可以为您完成所有这些工作: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.
与常规符号链接不同,您不能简单地删除文件夹来删除符号链接文件夹。如果你这样做,它会删除它指向的真实文件夹。所以使用时要格外小心。
回答by Ian Boyd
Yes, there is a way to map a UNC path to a local folder:
是的,有一种方法可以将 UNC 路径映射到本地文件夹:
C:\>mklink /D Develop \obsidian\Develop
symbolic link created for Develop <<===>> \obsidian\Develop
This is because i want a buildserver to use my own PC's Develop
folder as its Develop
folder:
这是因为我希望构建服务器使用我自己的 PCDevelop
文件夹作为其Develop
文件夹:
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 localresource.
注意:在我的实际情况中,我需要另一个级别的重定向,因为我使用的程序意识到这Develop
是一个符号链接,指向远程机器,并拒绝遵守。我告诉程序关闭并通过给它一个指向本地资源的连接点来做它告诉它的事情。
10/20/2012 11:06 AM <JUNCTION> Develop [C:\Develop2\]
10/20/2012 11:01 AM <SYMLINKD> Develop2 [\obsidian\Develop]
回答by Wulfhart
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.
net use e: \\shares\folder # 您需要将其设置为持久性,否则下次重新启动会破坏它。
Browse using cmd to your location you want the link
使用 cmd 浏览到您想要链接的位置
cd c:\folder
cd c:\文件夹
mklink /d name e:\
mklink /d 名称 e:\
Now anything that accesses c:\folder\name\ will be accessing \\shares\folder\
现在任何访问 c:\folder\name\ 的东西都将访问 \\shares\folder\
回答by dorbar
According to Microsoft YOU CAN NOT map a shared folder on a remote machine (server) to a local folder. For example:
根据微软的说法,你不能将远程机器(服务器)上的共享文件夹映射到本地文件夹。例如:
- shared folder on Server: \\Server\share1
- mapped share on a local machine: c:\MyProgram\Some_Useluf_Files_Here
- 服务器上的共享文件夹:\\Server\share1
- 本地机器上的映射共享:c:\MyProgram\Some_Useluf_Files_Here
This wil not work!!!! As Microsoft stated you CAN NOT do mklinkon a remote machine at least not for Junctionor Hard-links. You can ONLY do it as a Symboliclink 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 taht :-(
这行不通!!!!正如微软所说,你不能在远程机器上执行mklink至少不能用于Junction或Hard-links。您只能将其作为符号链接来执行,这基本上是一种快捷方式。因此,如果某个程序需要访问与服务器上相同的本地文件夹......对不起,运气不好!!Windows 不是 Linux 让我们不要忘记 taht :-(
回答by Remy Lebeau
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.
你不能直接映射它,不。您可以尝试实现注册为文件系统一部分的 Shell 命名空间扩展,以便您可以在需要的地方将其作为根目录,然后让它在内部访问 UNC 路径。实现不是一件微不足道的事情,但它应该会给你你正在寻找的最终结果。
回答by Leo Davidson
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:
假设您想将 \\moo\cow 映射到 C:\cow_files,并且还没有名为 moo 的服务器(如果有,您可以直接共享文件夹,所以我假设没有),您可以:
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.)
Share C:\cow_files as cow on that machine.
编辑主机文件(或您的实际 DNS,如果可以的话)以将 moo 映射到带有 C:\cow_files 的机器。(或者,如果目录是需要映射的客户端的本地目录,则指向 localhost。)
在该机器上将 C:\cow_files 共享为 cow。
You should then be able to map to \\moo\cow and get the files you need, unless I've missed something (which is possible :)).
然后您应该能够映射到 \\moo\cow 并获取您需要的文件,除非我遗漏了一些东西(这是可能的:))。
回答by Davin Studer
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.
经过多次尝试,我终于发现你不能按照我想要的方式去做。我在 Server 2008 中使用 mklink 功能尝试了符号链接,但结果是 .NET System.IO api 无法识别符号链接。因此,如果您在符号链接的文件夹上执行 Directory.GetFiles(),则会引发错误。