TLama

Untitled

Apr 13th, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.91 KB | None | 0 0
  1. function MapNetworkDrive(const LocalPath, RemotePath: string; UserName: PChar = nil;
  2.   Password: PChar = nil): DWORD;
  3. var
  4.   NetResource: TNetResource;
  5. begin
  6.   // this is quite paranoic zeroing of all members, even those that are ignored by the
  7.   // WNetAddConnection2 function
  8.   ZeroMemory(@NetResource, SizeOf(NetResource));
  9.  
  10.   NetResource.dwType := RESOURCETYPE_DISK;
  11.   NetResource.lpLocalName := PChar(LocalPath);
  12.   NetResource.lpRemoteName := PChar(RemotePath);
  13.   NetResource.lpProvider := nil;
  14.  
  15.   Result := WNetAddConnection2(NetResource, Password, UserName, CONNECT_UPDATE_PROFILE);
  16. end;
  17.  
  18. procedure TForm1.Button1Click(Sender: TObject);
  19. var
  20.   MapResult: DWORD;
  21. begin
  22.   MapResult := MapNetworkDrive('z:', '\\192.168.1.34\Downloads', PChar('UserName'),
  23.     PChar('passw0rd'));
  24.   if MapResult <> NO_ERROR then
  25.     ShowMessageFmt('Mapping of a network drive failed. Returned code %d.', [MapResult]);
  26. end;
Advertisement
Add Comment
Please, Sign In to add comment