首页 > 编程资源分享区 > C/C++源代码共享 > 如何映射网络驱动器
2006
07-05

如何映射网络驱动器

char netpath[MAX_PATH]=”\\\\Shichengming\\共享的硬盘 (H)”;//ZHOU 为机器名,F为共享的文件夹名或盘符名

char drv[32]=”H:”;

NETRESOURCE netres;
netres.dwScope =RESOURCE_GLOBALNET;
netres.dwType =RESOURCETYPE_ANY;
netres.dwDisplayType =RESOURCEDISPLAYTYPE_GENERIC;
netres.dwUsage =RESOURCEUSAGE_CONNECTABLE;
netres.lpLocalName = drv;
netres.lpRemoteName = netpath;
netres.lpComment =NULL;
netres.lpProvider =NULL;
DWORD  rslt=WNetAddConnection2(&netres,NULL,NU LL,FALSE);

if (rslt==NO_ERROR)
{
   CString str;
   str.Format (“WNetAddConnection2() return code=%d”,rslt);
   MessageBox(str);
}
else
AfxMessageBox(“erro”);
断开网络驱动器
char drv[256]=”H:”;

DWORD  rslt=WNetCancelConnection2(  drv, 0,FALSE);
CString str;
str.Format (“WNetCancelConnection2() return code=%d”,rslt);
MessageBox(str);

zcgzcg1@mail.china.com


留下一个回复