Article View: borland.public.cppbuilder.nativeapi
Article #4480Re: Mapping a network drive on Windows and Linux
From: Michael Gillen
Date: Mon, 30 Jan 2006 13:47
Date: Mon, 30 Jan 2006 13:47
43 lines
2244 bytes
2244 bytes
Bono wrote:
> I'm writing a CLX (multiplatform) Application and I need to connect to a
> remote network
> machine (I know the IP address).
> Does anybody know how can I map a network drive? Is it going to work on both
> (windows and linux) platforms?
This snippet of code works mapping to a network drive - Windows or Samba.
// We can map via IP address or system name
if(CbxUseIP->Checked)
RemoteName = "\\\\"+EdtIpAddress->Text+AnsiString(ShareName);
else
RemoteName = "\\\\"+EdtComputerName->Text+AnsiString(ShareName);
// An avilable drive letter was selected
AnsiString DriveName = CbxAvailDrives->Text.c_str();
NETRESOURCE nr;
DWORD dwFlags;
ZeroMemory(&nr, sizeof(nr));
nr.dwType = RESOURCETYPE_DISK;
nr.lpLocalName = DriveName.c_str();
nr.lpRemoteName = RemoteName.c_str();
dwFlags = NULL;
if(CbxRemember->Checked)
dwFlags = dwFlags | CONNECT_UPDATE_PROFILE;
Screen->Cursor = crHourGlass;
int rc;
rc = WNetAddConnection2(&nr,EdtPasswd->Text.c_str(), EdtUserName->Text.c_str(), dwFlags);
Screen->Cursor = crDefault;
if(rc != NO_ERROR)
{
// A special message for this
if(rc == ERROR_BAD_NETPATH)
MessageDlg("The network path cannot be found.", mtError, TMsgDlgButtons() << mbOK, 0);
else
GetLastErrorStr( rc );
return false;
}
--
-Michael Gillen
Technical Details
Message-ID:
<43de271f@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<43dded9d$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d7567c071b7d994a X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Michael Gillen" <michael@gillenconsultinggroup-nospam.com> Subject: Re: Mapping a network drive on Windows and Linux Newsgroups: borland.public.cppbuilder.nativeapi References: <43dded9d$1@newsgroups.borland.com> User-Agent: XanaNews/1.17.6.6 NNTP-Posting-Host: 67.122.199.249 Message-ID: <43de271f@newsgroups.borland.com> Date: 30 Jan 2006 06:47:59 -0700 X-Trace: newsgroups.borland.com 1138632479 67.122.199.249 (30 Jan 2006 06:47:59 -0700) Lines: 43 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail