I wrote the following to allow an application to map a drive dynamically so that the client computer doesn't have to have a permanently mapped drive.
The problem arises when the second mapping is executed. The "Error" messagebox comes up. I checked and V: has been mapped, but Z: has not. I commented out everything that maps V: and it works. There seems to be a problem mapping 2 drives at a time.
Any suggestions?
Also, how do I disconnect the mapped drives when the app finishes?
Code:
afx_msg void Dataplot_GUIDlg::MapDrive()
{
NETRESOURCE connV;
NETRESOURCE connZ;
DWORD V;
DWORD Z;
TCHAR szLocalVName[32] = "V:";
TCHAR szRemoteVName[MAX_PATH] = "\\\\mcriserver02\\dataplot";
TCHAR szVUserName[32] = "";
TCHAR szVPassword[32] = "";
TCHAR szLocalZName[32] = "Z:";
TCHAR szRemoteZName[MAX_PATH] = "\\\\mcriserver02\\cmm_files";
TCHAR szZUserName[32] = "";
TCHAR szZPassword[32] = "";
connV.dwType = RESOURCETYPE_ANY;
connV.lpLocalName = szLocalVName;
connV.lpRemoteName = szRemoteVName;
connV.lpProvider = NULL;
connZ.dwType = RESOURCETYPE_ANY;
connZ.lpLocalName = szLocalZName;
connZ.lpRemoteName = szRemoteZName;
connZ.lpProvider = NULL;
V = WNetAddConnection2(&connV, szVPassword, szVUserName, FALSE);
Z = WNetAddConnection2(&connZ, szZPassword, szZUserName, FALSE);
if(V==NO_ERROR && Z==NO_ERROR)
{
MessageBox("Connection added");
}
else
{
MessageBox("Error");
}
}
The problem arises when the second mapping is executed. The "Error" messagebox comes up. I checked and V: has been mapped, but Z: has not. I commented out everything that maps V: and it works. There seems to be a problem mapping 2 drives at a time.
Any suggestions?
Also, how do I disconnect the mapped drives when the app finishes?