如何映射带有用户名和密码的网络驱动器
请各位同仁指教,谢谢!
局域网的示例:
DECLARE LONG StrDup IN Shlwapi STRING@
DECLARE LONG WNetAddConnection2 IN Mpr.dll STRING@, STRING@, STRING@, LONG
DECLARE LONG WNetCancelConnection2 IN Mpr.dll STRING@, LONG, LONG
IF _NetConnect("", "\\192.168.0.250\Test$", "UserName", "PassWord")
USE \\192.168.0.250\Test$\temp.dbf
BROWSE
USE
WNetCancelConnection2("\\192.168.0.250\Test$", 0, 1)
ENDIF
**
** 连接局域网共享文件夹
** szLocalName ... 影射到本地设备,如 X:,为空时不映射为盘符,空连接。
** szRemoteName .. 连接的远程设备,如 \\server\共享文件夹$
**
FUNCTION _NetConnect(szLocalName, szRemoteName, szUserName, szPassWord)
LOCAL stNR, ddRet, szMsg
stNR = REPLICATE(0h00, 4);
+ BINTOC(1, "4RS");
+ REPLICATE(0h00, 8);
+ BINTOC(StrDup(@szLocalName), "4RS");
+ BINTOC(StrDup(@szRemoteName), "4RS");
+ REPLICATE(0h00, 8)
ddRet = WNetAddConnection2(@stNR, @szPassWord, @szUserName, 1)
IF ddRet == 1219 && 已经有连接,断开再连接。
WNetCancelConnection2(@szRemoteName, 0, 1)
ddRet = WNetAddConnection2(@stNR, @szPassWord, @szUserName, 1)
ENDIF
IF ddRet != 0
szMsg = ICASE(ddRet == 5, "找不到 " + szRemoteName + " 设备",;
ddRet == 85, "本地设备 " + szLocalName + " 已经连接",;
ddRet == 66, "本地设备 " + szLocalName + " 类型不匹配",;
ddRet == 1200, "指定的设备 " + szLocalName + " 名称无效",;
ddRet == 67, "找不到 " + szRemoteName + " 网络名称",;
ddRet == 1206, "调用WNetAddConnection2()的配置文件格式不正确",;
ddRet == 1204, "网络设备 " + szRemoteName + " 名称无效",;
ddRet == 2202, "网络设备 " + szUserName + " 用户名无效",;
ddRet == 170, "网络忙,请重试",;
ddRet == 1223, "连接被取消",;
ddRet == 1205, "调用WNetAddConnection2()无法打开用户配置文件",;
ddRet == 1202, "本地设备 " + szLocalName + " 与其他网络资源已经连接",;
ddRet == 1208, "发生网络错误,可用WNetGetLastError()函数获得错误信息。",;
ddRet == 487, "资源结构的lpLocalName成员未指定 " + szLocalName,;
ddRet == 87, "资源结构的dwtype成员参数不正确",;
ddRet == 86, "用户名或密码无效",;
ddRet == 1326, "用户名或密码无效",;
ddRet == 1203, "网络设备 " + szRemoteName + " 不被接受",;
ddRet == 1222, "网络不可用", "登录连接异常")
MESSAGEBOX(szMsg, "提示")
ENDIF
RETURN (ddRet == 0)
ENDFUNC