检查网络驱动器上是否存在目录 [英] Check if directory exists on Network Drive

查看:35
本文介绍了检查网络驱动器上是否存在目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检测目录是否存在,但在这种特殊情况下,我的目录是一个网络位置.我使用了 VB.NET 的 My.Computer.FileSystem.DirectoryExists(PATH) 和更通用的 System.IO.Directory.Exists(PATH),在这两种情况下,系统响应为假.我检查过路径存在,我可以在 MyComputer 文件夹中查看它.如果我调试程序并观察 My.Computer.FileSystem.Drives 变量,网络位置不会出现在该列表中.

I'm trying to detect if the directory exists, but in this particular situation my directory is a network location. I used VB.NET's My.Computer.FileSystem.DirectoryExists(PATH) and the more general System.IO.Directory.Exists(PATH), and in both cases, the system response is false. I checked and the PATH exists, I can view it in MyComputer Folder. If I debug the program, and watch the My.Computer.FileSystem.Drives variable, the network location does not appear in that list.

更新:我检查过,在 Windows XP 中响应为 True,但在 Windows 7 中不是.

UPDATE: I checked and in Windows XP the Response is True, but not in Windows 7.

UPDATE2: 我测试了两个提议的解决方案,但我仍然遇到同样的问题,在下图中您会看到我可以使用资源管理器访问,但我的程序不能.GetUNCPath 函数返回有效路径(无错误),但 Directory.Exists stil 返回 false.

UPDATE2: I tested both proposed solutions but I still have the same problem, on the image below you will see that I can access using Explorer but my program cannot. The GetUNCPath function returns a valid path (no errors), but Directory.Exists stil returns false.

我也尝试过使用 UNC 路径\ServerImages";相同的结果.

I also tried with the UNC path "\ServerImages"; same result.

UPDATE3:如果我无法与网络驱动器链接,如何直接链接到 UNC 路径?.我发现如果我在正常模式下运行 VS,它可以工作,但我的软件必须在管理员模式下运行.那么,有没有办法以管理员身份检查网络目录是否存在?

UPDATE3: If I cannot link with a network drive, how can I link to UNC path directly?. I discovered that if i run VS in normal mode, it works, but my software must run in administrator mode. So, there is any way to check the existence of a network directory as administrator?

推荐答案

如果 UAC 已打开,则映射的网络驱动器仅默认"存在于它们所映射的会话中:正常或提升.如果您从资源管理器映射网络驱动器,然后以管理员身份运行 VS,该驱动器将不存在.

If UAC is turned on, mapped network drives only exist "by default" in the session they are mapped: Normal or elevated. If you map a network drive from explorer, then run VS as admin, the drive will not be there.

您需要启用 MS 所谓的链接连接":HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionPoliciesSystem: EnableLinkedConnections (REG_DWORD) = 0x1

You need to enable what MS calls "linked connections": HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionPoliciesSystem: EnableLinkedConnections (REG_DWORD) = 0x1

有关使用 UAC 的两次登录会话"的背景信息:http://support.microsoft.com/kb/937624/en-us

Background Information about "two logon sessions" with UAC: http://support.microsoft.com/kb/937624/en-us

这篇关于检查网络驱动器上是否存在目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆