有没有办法将 UNC 路径映射到 Windows 2003 上的本地文件夹?

发布于 2024-10-06 02:29:18 字数 154 浏览 1 评论 0原文

我知道我可以将 UNC 路径映射到本地驱动器号。但是,我想知道是否有办法将 UNC 路径映射到本地文件夹。我有一个程序,其中硬编码到程序中的特定文件夹,我想尝试创建一个映射到 UNC 路径的同名文件夹,以便可以从网络共享访问数据。这可行吗?具体来说,这是在 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

自此以后,行同陌路 2024-10-13 02:29:18

是的,有一种方法可以将 UNC 路径映射到本地文件夹:

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

这是因为我希望 build 服务器使用我自己 PC 的 Develop 文件夹作为其 Develop 文件夹:

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

这就是它。


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.

注意:在我的实际情况中,我需要另一个级别的重定向,因为我正在使用的程序意识到Develop是一个符号链接,指向到远程机器,并拒绝遵守。我告诉程序关闭并通过给它一个指向本地资源的连接来执行它所指示的操作。

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

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]
凹づ凸ル 2024-10-13 02:29:18

这完全符合OP的要求——映射到网络共享的Windows 2003的符号链接。经过几个小时的观察和测试其他组件后,我发现这是唯一可以与网络共享一起使用的组件。

Windows XP 的符号链接驱动程序

此实用程序适用于 XP 和 2003 映射到网络共享并创建符号链接:http://schinagl.priv.at/nt/ln/ln.html#symboliclinksforwindowsxp

现在将其放入路径上的目录中,您就可以使用 senable 创建符号链接。 exe(带有symlink.sys)和ln.exe(您还需要从上述站点获取它以及它对 Visual C++ 运行时 DLL 的依赖项)。

添加的奖励:伪造 MkLink

将这两个附加文件放入具有 senable.exe 的同一目录中,并确保它们全部位于路径中。

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"

注意:

您需要在 Windows 2003 上安装以下其他项目(非 R2,我还不确定 R2 需要什么):

  • Microsoft .NET Framework 2.0 Service Pack 1
  • Windows 成像组件
  • Windows Server 2003 Service Pack 2
  • Windows Management Framework Core(这带来了 PowerShell 2)

Chocolatey 包

我创建了一个 Chocolatey 包,它将为您完成所有这些操作:http://chocolatey.org/packages/win2003-mklink

重要提示

与常规符号链接不同,您不能简单地删除文件夹来删除符号链接文件夹。如果这样做,它将删除它指向的真实文件夹。因此使用时要格外小心。

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.

有深☉意 2024-10-13 02:29:18

您不能直接执行此操作,但如果您创建符号链接,您应该能够将其指向映射的驱动器号。

net use e: \\\\shares\folder # 您需要将其设置为持久,否则下次重新启动将破坏它。

使用 cmd 浏览到您想要链接的位置:

cd c:\folder

mklink /d name e:\

现在访问 的任何内容>c:\folder\name\ 将访问 \\\\shares\folder\

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\

無心 2024-10-13 02:29:18

根据 Microsoft 的说法,您无法将远程计算机(服务器)上的共享文件夹映射到本地文件夹。

例如,这将不起作用:

  • 服务器上的共享文件夹:\\\Server\share1
  • 本地计算机上的映射共享:c:\MyProgram\Some_Useful_Files_Here

正如 Microsoft 所说,你不能在远程机器上执行mklink;至少对于Junction硬链接来说是这样。您只能将其作为符号链接来执行,这基本上是一个快捷方式。

因此,如果某个程序需要访问与服务器上相同的本地文件夹,抱歉,运气不好! Windows 不是 Linux,我们不要忘记这一点:-(

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 :-(

旧伤还要旧人安 2024-10-13 02:29:18

你不能直接映射它,不。您可以尝试实现一个注册为文件系统一部分的 Shell 命名空间扩展,以便您可以在需要的地方对其进行 root,然后让它在内部访问 UNC 路径。实施起来并不是一件小事,但它应该会给您带来您正在寻找的最终结果。

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.

谎言月老 2024-10-13 02:29:18

经过多次尝试,我终于发现你无法按照我想要的方式做到这一点。我尝试使用 Server 2008 中的 mklink 功能建立符号链接,但事实证明 .NET System.IO API 无法识别符号链接。

因此,如果您对符号链接的文件夹执行Directory.GetFiles(),则会抛出错误。

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.

小鸟爱天空丶 2024-10-13 02:29:18

假设您想要将 \\moo\cow 映射到 C:\cow_files,并且还没有名为 moo 的服务器(如果有,您可以共享该文件夹直接,所以我假设没有),您可以:

  1. 编辑主机文件(或者您的实际 DNS,如果可以的话)以将 moo 映射到具有 C:\ 的计算机就可以了。 (或者如果目录位于需要映射的客户端本地,则为 localhost。)


  2. 在该计算机上将 C:\cow_files 共享为 cow

然后,您应该能够映射到 \\moo\cow 并获取您需要的文件,除非我错过了某些内容(这是可能的:))。

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 :)).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文