16,471
社区成员
发帖
与我相关
我的任务
分享
int MappingNetDriver()
{
// TODO: 在此添加控件通知处理程序代码
char buf[256];
NETRESOURCE nr;
DWORD res;
TCHAR szUserName[32] = "",
szPassword[32] = "",
szLocalName[32] = "S:",
szRemoteName[MAX_PATH] = "\\\\192.168.169.1\\huaxiayou";
//FindUnusedDriver(szLocalName);
// Assign values to the NETRESOURCE structure.
//
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = szLocalName;
nr.lpRemoteName = szRemoteName;
nr.lpProvider = NULL;
//
// Call the WNetAddConnection2 function to assign
// a drive letter to the share.
//
res = WNetAddConnection2(&nr, NULL, NULL, FALSE);
if(NO_ERROR == res)
{
::MessageBox(NULL, "连接成功。", "",
MB_OK|MB_SERVICE_NOTIFICATION);
}
else
{
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(), 0, buf, sizeof(
buf), 0);
::MessageBox(0, buf, "", MB_SERVICE_NOTIFICATION);
}
return 0;
}