Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mapping Drives - HELP!

Status
Not open for further replies.

fdsouth

Technical User
Jun 6, 2001
61
US
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.

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?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top