Главная страница | назад





Article #17585: Mapping a network drive programmatcally.

 Question and Answer Database
FAQ2585C.txt Mapping a network drive programmatcally.
Category :Windows API
Platform :All
Product :C++Builder 3.x
Question:
How do I programatically map a network drive?
Answer:
Like this:
//---------------------------------------------------------------
NETRESOURCE netResource;
ZeroMemory(&netResource, sizeof(NETRESOURCE));
netResource.dwType = RESOURCETYPE_DISK;
netResource.lpLocalName = "Q:";
netResource.lpRemoteName = "\\\\SPIKE\\homedir";
if(WNetAddConnection2(&netResource, "firebird", "djf", NULL) != NO_ERROR)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0,
NULL);
MessageBox(Application->Handle,
(const char *)lpMsgBuf,
"GetLastError",
MB_OK | MB_ICONINFORMATION);
LocalFree(lpMsgBuf);
}
//---------------------------------------------------------------
7/2/98 10:32:32 AM

Last Modified: 01-SEP-99