Access to a shared folder from remote server lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- SteenJorgensen · 2021-08-10 07:41 Hi I have some shared directory from another server i need to connect, and sometimes username and password is needed for access. How can i send username/password for the share. Without making a new process and execute "Net use "\\myShare" "Mypasswd" /User:Username" eg.: If not DirectoryExists(\\myshare) then   SetUpMyShare; <-- Needed procedure FindAllFiles(slFiles, '\\myshare', '*.*', true); ---------------------------------------------------------------------- af0815 · 2021-08-10 12:09 You mean a soloution for windows only or from linux ? Windows only, you can call the Windows-API functions to handle the shares like the 'net use'. Here an old snippet for example. I don't know if it works with the actual fpc/lazarus and maybe win32 only. https://docs.microsoft.com/en-us/windows/win32/api/winnetwk/nf- winnetwk-wnetaddconnection2a Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit WNNetShare; {$mode objfpc}{$H+} interface uses  Classes, SysUtils; function ConnectNetworkDrive(const ADrive: String;  const ADirectory, AUsername, APassword: String;  const ARestoreAtLogon: Boolean ): Boolean; procedure DisconnetNetworkDrive(const ADrive: String);  implementation uses  windows; function ConnectNetworkDrive(const ADrive: String;  const ADirectory, AUsername, APassword: String;  const ARestoreAtLogon: Boolean ): Boolean;var  NetResource: TNetResource;  dwFlags:     DWORD;  lPwd, lUser: PChar;begin  NetResource.dwType:=RESOURCETYPE_DISK;  NetResource.lpLocalName:=PChar(ADrive);  NetResource.lpRemoteName:=PChar(ADirectory);  NetResource.lpProvider:=nil;   if ARestoreAtLogon then    dwFlags:=CONNECT_UPDATE_PROFILE  else    dwFlags:=0;  if AUsername = '' then    lUser:=PChar(AUsername)  else    lUser:=nil;  if APassword = '' then    lPwd:=PChar(APassword)  else    lPwd:=nil;  Result:=WNetAddConnection2(NetResource,                             lPwd,                             lUser,                             dwFlags)=NO_ERROR;end; procedure DisconnetNetworkDrive(const ADrive: String);begin  if not WNetCancelConnection2(PChar(ADrive),0, True)=NO_ERROR then    RaiseLastOSError;end;  end.