WNetAddConnection2调用失败,错误码1200/1312

使用WNetAddConnection2实现磁盘映射,代码如下:

CString m_strImageHostPath = L"\\10.27.162.38\share_file";
CString m_strLocalImagePath = L"Z:";
CString m_strImagePwd = L"stadmin";
CString m_strImageUser = L"123456";

DWORD   dwResult;  
NETRESOURCE   nr;
memset(&nr, 0, sizeof(nr));
nr.dwScope=RESOURCE_CONNECTED;
nr.dwType=RESOURCETYPE_ANY;
nr.dwDisplayType=RESOURCEDISPLAYTYPE_GENERIC;
nr.dwUsage=RESOURCEUSAGE_CONNECTABLE;
nr.lpRemoteName = (LPTSTR)(LPCTSTR)m_strImageHostPath;
nr.lpLocalName = (LPTSTR)(LPCTSTR)m_strLocalImagePath;
dwResult = WNetAddConnection2(&nr, m_strImagePwd,  m_strImageUser, CONNECT_UPDATE_PROFILE);

1、错误码1200:指定的设备名无效
原因:在配置文件中,磁盘映射本地地址为Z:/,改为Z:即可
2、错误码1312:指定的登录会话不存在。可能已被终止;
原因:可能是当前软件启动启动用户问题,服务启动时默认的都是 “system” 用户,导致连接共享目录失败,改由"system" 用户启动即可;

你可能感兴趣的:(Windows,C++错误集)