Rede - conectando drives |
Top Previous Next |
|
Para mostrar a caixa de dialogo para mapear a unidade de rede:
WNetConnectionDialog(Handle,RESOURCETYPE_DISK );
===================================================================
Rotinas para mapear/desconectar via programação: ------------------------------------------------
function NetDriveConnect(const Drive, NetworkPath, User, Password: string): Boolean; var nrResource: Tnetresource; begin nrResource.dwType := ResourceType_Disk; nrResource.lpLocalName := PChar(Drive); nrResource.lpRemoteName:= PChar(NetworkPath); nrResource.lpProvider := nil; Result := (WNetAddConnection2(nrResource,PChar(Password),PChar(User),0) = NO_ERROR); end;
function NetDriveDisconnect(const Drive: string): Boolean; begin Result:= WNetCancelConnection2(PChar(Drive),0,True) = NO_ERROR; end;
Exemplo de uso: ---------------
// conecta if NetDriveConnect('W:','\\COMPUTADOR2\C','JUNIOR','211234') then ShowMessage('OK') else ShowMessage('ERROR');
// desconeta if NetDriveDisconnect('W:') then ShowMessage('OK') else ShowMessage('ERROR');
=================================================================== // OUTRO
var NetResource : TNetResource; begin with NetResource do begin dwType := RESOURCETYPE_DISK; lpLocalName := 'I:'; lpRemoteName := '\\ANA\E'; lpProvider := nil; end; WNetAddConnection2(NetResource,nil,nil,0); end;
|