分类: WINDOWS
2005-10-17 16:00:15
第四节:映射盘符驱动器
//szUserName[32] = "myUserName", //以NULL结尾的字符串(用户名)
//szPassword[32] = "myPassword", //以NULL结尾的字符串(口令)
//szLocalName[32] = "Q:", //本地驱动器号
//szRemoteName[MAX_PATH] = ""; //远程机器名称
//Add the file to a console application called AddConn2 and link the library MPR.LIB to
//the compiler list of libraries. Then, run the file AddConn2.EXE after you compile the
//following program.
//编译时加入MPR.LIB库就可
#include
#include
#include
void main()
{
NETRESOURCE nr;
DWORD res;
TCHAR szUserName[32] = "MyUserName",
szPassword[32] = "MyPassword",
szLocalName[32] = "Q:",
szRemoteName[MAX_PATH] = "";
//填充结构NETRESOURCE(调用WNetAddConnection2函数要用的)
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = (LPTSTR) &szLocalName;
nr.lpRemoteName = (LPTSTR) &szRemoteName;
nr.lpProvider = NULL;
res = WNetAddConnection2(&nr, (LPTSTR) &szPassword, (LPTSTR) &szUserName, FALSE);
if(res == NO_ERROR)
printf("连接已经完成,盘符为Q:
", szRemoteName);
else
printf("错误: %ld
", res); //也可在此加入第三节的错误判断一部分
return;
}
;====汇编语言描述(BY 谢小荣)=====
include masm32includeMPR.inc
include masm32include
etapi32.inc
includelib masm32libMPR.lib
includelib masm32lib
etapi32.lib
AsmWNetAddConnection2 PROTO :DWORD,:DWORD,:DWORD,:DWORD
.data
msg_err1 db "有错!",0
err_code dd 0
.code
AsmWNetAddConnection2 proc hwnd:DWORD,hdc:DWORD,szPassword:DWORD,szUserName:DWORD,nr:DWORD
invoke WNetAddConnection2,nr,szPassword,szUserName,FALSE
.if eax==NO_ERROR
mov eax,0
.else
mov err_code,eax
invoke TextOut,hdc, 10, 10, addr msg_err1, 10
mov eax,err_code
.endif
ret
AsmWNetAddConnection2 endp