KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Mount or map a network path using LEP
PRODUCT: 4D | VERSION: 14.1 | PLATFORM: Mac & Win
Published On: December 23, 2014

Here is an method to mount or map a network path using LAUNCH EXTERNAL PROCESS:

// ----------------------------------------------------------------------
// Name: MOUNT_MAP_NETWORK_PATH
// Description: Connects to a network drive path by mounting on Mac or
// assigning a map drive letter in Windows using LAUNCH EXTERNAL PROCESS.
//
// Parameters:
// $1 (TEXT) - Server path to connect to mount/map
// $2 (TEXT) - Username
// $3 (TEXT) - Password
// $4 (TEXT) - Assigning a Drive letter (Optional for Mac)
//
// Output:
// $0 (TEXT) - Status ("Success" - No error, "ERROR" - Not enough
// parameter, or error from LAUNCH EXTERNAL PROCESS)
// ----------------------------------------------------------------------
C_TEXT($1;$server_path)
C_TEXT($2;$username)
C_TEXT($3;$password)
C_TEXT($4;$win_drive_assign)
C_TEXT($0)
C_TEXT($LEP_Command;$in;$out;$error)


If (Count parameters>2)
   $server_path:=$1
   $username:=$2
   $password:=$3
   $win_drive_assign:=$4

   If (Folder separator=":") // mac
      $LEP_Command:="open smb://"+$username+":"+$password+"@"+$server_path
      $in:=""
      LAUNCH EXTERNAL PROCESS($LEP_Command;$in;$out;$error)

      If ($error="")
         $0:="Success" // success
      Else
         $0:=$error // error on the LAUNCH EXTERNAL PROCESS
      End if

   Else
      $LEP_Command:="net use "+$win_drive_assign+": \\\\"+$server_path+"       /user:"+$username+" "+$password
      $in:=""
      LAUNCH EXTERNAL PROCESS($LEP_Command;$in;$out;$error)

      if ($error="")
         $0:="Success" //success
      Else
         $0:=$error // error on the LAUNCH EXTERNAL PROCESS
      End if

   End if
Else
   $0:="ERROR: Not enough input parameters" // Not enough parameters
End if



Here is a example of mounting a network path for a Mac:

C_TEXT($status)

$status:=MOUNT_MAP_NETWORK_PATH ("serverName\Images";"username";"password";"")




Here is an example of mapping a drive "Z:" of a network path for Windows:

C_TEXT($status)

$status:=MOUNT_MAP_NETWORK_PATH ("serverName\Images";"username";"password";"Z")




Commented by Magnus Torell on March 31, 2018 at 7:52 AM
Dear, I am using this code. However it seems to never hit the unsuccessful case. Even if the login fails there is no error presented. What am I missing? I am running the code in v15 R5 on mac. Best Regards Magnus Torell