我试图使用WNetAddCOnnection2
映射驱动器,但有些事情不太正确。我使用的代码从pinvoke.net开始似乎工作。如果我单步执行代码,我会得到一个0作为响应,并且我可以使用System.IO.Directory.GetFiles()
来检查新的映射驱动器,这使我相信证书是正确的。无法访问使用WNetAddConnection2添加映射驱动器
问题是驱动器在应用程序之外不可用。当我从命令提示符下键入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。