Map network drive  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 22/01/00

Tip accessed 717 times

 


The easiest thing is to call to map network drive dialog WNetConnectionDialog()

Example:


   procedure TForm1.Button1Click(Sender: TObject);
   begin
     WNetConnectionDialog(Handle,RESOURCETYPE_DISK);
   end;




If we want to connect a printer:


   procedure TForm1.Button1Click(Sender: TObject);
   begin
     WNetConnectionDialog(Handle,RESOURCETYPE_PRINT);
   end;




If what we want is to connect it... without showing any dialog:


           procedure TForm1.Button2Click(Sender: TObject);
           var
             NetResource: TNetResource;
           begin

             { fill our TNetResource record structure }
             NetResource.dwType       := RESOURCETYPE_DISK;
             NetResource.lpLocalName  := 'S:';
             NetResource.lpRemoteName := '\\server\public';
             NetResource.lpProvider   := '';

             { map our network drive using our TNetResource
               record structure }
             WNetAddConnection2(NetResource,
                                '', {Clave o vacio /Password or empty}
                                '', {Nombre del usurio o vacio/User name o vacio}
                                CONNECT_UPDATE_PROFILE);
           end;



In the example, we will connect '\\server\public' to S:, without username neither password



How disconnect a shared unit



 procedure TForm1.Button2Click(Sender: TObject);
 begin
   if WNetCancelConnection2( 'S:',0,TRUE) <> NO_ERROR then
     Raise Exception.create('Error al desconectar la unidad');
 end;




Updated at 22/01/2000