【发布时间】:2010-12-14 18:27:38
【问题描述】:
我正在尝试使用WNetAddCOnnection2 映射驱动器,但有些地方不太对劲。我使用的代码来自pinvoke.net,起初似乎可以工作。如果我单步执行代码,我会得到一个 0 作为响应,并且我可以使用 System.IO.Directory.GetFiles() 检查新映射的驱动器,这让我相信凭据很好。
问题是驱动器在应用程序之外不可用。当我在命令提示符下键入 net use 时,我会看到这样列出的驱动器:
Unavailable L: \\<server>\<share> Microsoft Windows Network
当我尝试访问驱动器时,我得到:
The system cannot find the drive specified.
或
The system cannot find the path specified.
任何帮助将不胜感激。
以下是相关代码的简要说明:
NETRESOURCE res = new NETRESOURCE();
res.iScope = RESOURCE_GLOBALNET;
res.iType = RESOURCETYPE_DISK;
res.iDisplayType = RESOURCEDISPLAYTYPE_SHARE;
res.iUsage = RESOURCEUSAGE_CONNECTABLE;
res.sRemoteName = share;
res.sLocalName = drive;
res.sProvider = null;
int iFlags = 0;
iFlags = CONNECT_UPDATE_PROFILE;
int iResult = WNetAddConnection2( ref res, psPassword, psUsername, iFlags );
iResult 总是以 0 结束。
【问题讨论】:
标签: network-programming drive-mapping