Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function MapNetworkDrive(const LocalPath, RemotePath: string; UserName: PChar = nil;
- Password: PChar = nil): DWORD;
- var
- NetResource: TNetResource;
- begin
- // this is quite paranoic zeroing of all members, even those that are ignored by the
- // WNetAddConnection2 function
- ZeroMemory(@NetResource, SizeOf(NetResource));
- NetResource.dwType := RESOURCETYPE_DISK;
- NetResource.lpLocalName := PChar(LocalPath);
- NetResource.lpRemoteName := PChar(RemotePath);
- NetResource.lpProvider := nil;
- Result := WNetAddConnection2(NetResource, Password, UserName, CONNECT_UPDATE_PROFILE);
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- var
- MapResult: DWORD;
- begin
- MapResult := MapNetworkDrive('z:', '\\192.168.1.34\Downloads', PChar('UserName'),
- PChar('passw0rd'));
- if MapResult <> NO_ERROR then
- ShowMessageFmt('Mapping of a network drive failed. Returned code %d.', [MapResult]);
- end;
Advertisement
Add Comment
Please, Sign In to add comment