本文介绍了如何确定映射驱动器的实际路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何确定映射驱动器的实际路径?
How do I determine a mapped drive's actual path?
因此,如果我在名为Z"的机器上有一个映射驱动器,我如何使用 .NET 确定映射文件夹的机器和路径?
So if I have a mapped drive on a machine called "Z" how can I using .NET determine the machine and path for the mapped folder?
代码可以假设它在带有映射驱动器的机器上运行.
The code can assume it's running on the machine with the mapped drive.
我查看了 Path、Directory、FileInfo 对象,但似乎找不到任何东西.
I looked at Path, Directory, FileInfo objects, but can't seem to find anything.
我还查找了现有问题,但找不到我要查找的内容.
I also looked for existing questions, but could not find what I'm looking for.
推荐答案
以下是一些代码示例:
所有的魔法都来自于一个 Windows 函数:
All of the magic derives from a Windows function:
[DllImport("mpr.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int WNetGetConnection(
[MarshalAs(UnmanagedType.LPTStr)] string localName,
[MarshalAs(UnmanagedType.LPTStr)] StringBuilder remoteName,
ref int length);
示例调用:
var sb = new StringBuilder(512);
var size = sb.Capacity;
var error = Mpr.WNetGetConnection("Z:", sb, ref size);
if (error != 0)
throw new Win32Exception(error, "WNetGetConnection failed");
var networkpath = sb.ToString();
这篇关于如何确定映射驱动器的实际路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!