检查目录存在于网络驱动器 [英] Check if directory exists on Network Drive
问题描述
我试图来检测,如果该目录存在,但在这种特殊情况下我的目录是一个网络位置。
我用VB.NET的 My.Computer.FileSystem.DirectoryExists(PATH)
和更普遍的 System.IO.Directory.Exists(PATH)
,在这两种情况下,系统的响应是假的。
我查了一下路径存在,我可以在我的电脑文件夹中查看。
如果我调试程序,并观看 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中的反应是真实的,但不是在Windows 7
UPDATE: I checked and in Windows XP the Response is True, but not in Windows 7.
UPDATE2:我测试了提出的解决方案,但我仍然有同样的问题,在图像上下面你会看到,我可以访问使用浏览器,但我的程序不能。
该 GetUNCPath
函数返回一个有效的路径(没有错误),但 Directory.Exists
还是老样子返回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路径\\服务器\图像;同样的结果。
I also tried with the UNC path "\\Server\Images"; 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_MACHINE \ SOFTWARE \微软\的Windows \ CurrentVersion \政策\系统:EnableLinkedConnections(REG_DWORD)=为0x1
You need to enable what MS calls "linked connections": HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System: EnableLinkedConnections (REG_DWORD) = 0x1
有关与UAC两登录会话背景资料:<一href="http://support.microsoft.com/kb/937624/en-us">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屋!