Board index » delphi » How do you map a network drive?

How do you map a network drive?

 Anybody can tell me how to map a network drive from a delphi 3 app
(like the map network drive option in explorer). I have the name of
the new network connection, and until i find a better way, i resort to
using the dos prompt in a batch procedure (which is really slowwww).
Anybody can help?

Francis
please reply by email also to deric...@cnmtl2.cn.ca

 

Re:How do you map a network drive?


In article <3577d539.154996...@news.cn.ca>
deric...@cnmtl2.cn.ca (Francis De Rico) wrote:

Quote
>  Anybody can tell me how to map a network drive from a delphi 3 app
> (like the map network drive option in explorer). I have the name of
> the new network connection, and until i find a better way, i resort to
> using the dos prompt in a batch procedure (which is really slowwww).

Use the  WNetAddConnection2 API call.

Best regards, The Chief
--------
Dr. A{*word*73}la A. Olowofoyeku (The African Chief)
Email: la...@keele.ac.uk
Homepage: http://ourworld.compuserve.com/homepages/African_Chief/
Author of: Chief's Installer Pro v4.25 for Win16 and Win32:
ftp://ftp.demon.co.uk/pub/ibmpc/win3/apps/chief/pro/chief425.zip

Re:How do you map a network drive?


Quote
Francis De Rico wrote:

>  Anybody can tell me how to map a network drive from a delphi 3 app
> (like the map network drive option in explorer). I have the name of
> the new network connection, and until i find a better way, i resort to
> using the dos prompt in a batch procedure (which is really slowwww).
> Anybody can help?

> Francis
> please reply by email also to deric...@cnmtl2.cn.ca

This worked for me:

function NetDriveConnect(aDriveLetter : string; aNetwork_PathName :
string ;
 aUser_ID : string ; aPassword : string): Boolean;

function NetDriveDisConnect(aDriveLetter : string) : Boolean;

implementation

(* NetDrive Connect *)
{--------------------------------------------------------------------------------}
function NetDriveConnect(aDriveLetter : string; aNetwork_PathName :
string ;
 aUser_ID : string ; aPassword : string): Boolean;
var
  nrResource : Tnetresource;
  dwResult   : dword;

begin
  nrResource.dwType := ResourceType_Any;
  nrResource.lplocalname := pchar(aDriveLetter);
  nrResource.lpremotename := pchar(aNetwork_PathName);
  nrResource.lpprovider := nil;
         //     USERID   and    PASSWORD
  dwResult :=
WNetAddConnection2(nrResource,pchar(aUser_ID),pchar(aPassword),0);

  NetDriveConnect := true;
  iF dwResult<>NO_ERROR THEN
    begin
      NetDriveConnect := false;
    end;

end;

{-------------------------------------------------------------}
(* NetDrive DisConnect *)
function NetDriveDisConnect(aDriveLetter : string) : Boolean;
var
  dwResult : dword;
begin
  dwResult := WNetCancelConnection2(pchar(aDriveLetter),0,true);

  NetDriveDisConnect := true;
  if dwResult<>NO_ERROR THEN
    begin
      NetDriveDisConnect := false;
    end;

end;

Hope that helps!

Rkr

--
                   \|||/
                   /'^'\
                  ( 0 0 )
--------------oOOO--(_)--OOOo--------------
. Reid Roman                              .
. Delphi Programmer / Analyst             .
. TVisualBasic:=class(None);              .
. May the Source be With You              .
-------------------------------------------
. Auto-By-Tel (http://www.autobytel.com)  .
. Irvine, CA U.S.A                        .
. E-Mail : rkroman (at) pacbell (dot) net .
. or reidr (at) autobytel (dot) com       .
-------------------------------------------

Re:How do you map a network drive?


Try

WNetConnectionDialog( hwnd,  // handle to window owning dialog box
                                           dwType  // resource type to allow
connections to );

with dwType = RESOURCETYPE_DISK

Rob.

Francis De Rico ha scritto nel messaggio <3577d539.154996...@news.cn.ca>...

Quote
> Anybody can tell me how to map a network drive from a delphi 3 app
>(like the map network drive option in explorer). I have the name of
>the new network connection, and until i find a better way, i resort to
>using the dos prompt in a batch procedure (which is really slowwww).
>Anybody can help?

>Francis
>please reply by email also to deric...@cnmtl2.cn.ca

Other Threads