看看这样能否满足要求
主机IP:192.168.1.7
主机名:abcd
主机密码:1234
共享名:temp
共享文件:test.txt
共享权限:读写
程序代码:
DECLARE long _strdup IN msvcrt as apiStrdup string@
DECLARE long free IN msvcrt as apiFree long
DECLARE long WNetAddConnection2 IN mpr as apiWNetAddConnection2 string@,string@,string@,long
DECLARE long WNetCancelConnection2 IN mpr as apiWNetCancelConnection2 string@,long,long
cRemoteName = "\\192.168.1.7\temp"
IF myNetConnect(cRemoteName, "abcd", "1234")
MODIFY FILE (cRemoteName+"\test.txt")
apiWNetCancelConnection2(cRemoteName, 1, 1)
ENDIF
CLEAR ALL
RETURN
FUNCTION myNetConnect(cRemoteName, cUserName, cPassWord)
LOCAL tNR, nRet, pRemoteName
pRemoteName = apiStrdup(cRemoteName)
tNR = REPLICATE(0h00,4) + BINTOC(1,"4RS") + REPLICATE(0h00,12);
+ BINTOC(pRemoteName,"4RS") + REPLICATE(0h00,8)
nRet = apiWNetAddConnection2(@tNR, cPassWord, cUserName, 1)
IF nRet == 1219
apiWNetCancelConnection2(cRemoteName, 1, 1)
nRet = apiWNetAddConnection2(@stNR, cPassWord, cUserName, 1)
ENDIF
apiFree(pRemoteName)
IF nRet != 0
MESSAGEBOX("连接失败:"+TRANSFORM(nRet), "提示")
ENDIF
RETURN (nRet == 0)
ENDFUNC
[此贴子已经被作者于2022-1-26 18:51编辑过]