aqFileSystem.MapNetworkDrive Method

Applies to TestComplete 15.45, last modified on December 01, 2022

Description

Use the MapNetworkDrive method to establish connection to a network resource and redirect a local device to that resource.

Declaration

aqFileSystem.MapNetworkDrive(LocalName, Path, User, Password, Remember)

LocalName [in]    Required    String    
Path [in]    Required    String    
User [in]    Optional    String Default value: Empty string   
Password [in]    Optional    String Default value: Empty string   
Remember [in]    Optional    Boolean Default value: True   
Result Integer

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

LocalName

Specifies the name of the local device to redirect the network resource to, for example, “Z:”. If this parameter is not specified or contains an empty string, the connection to the remote resource is created, but no local device is redirected to that resource.

Path

Specifies the UNC path of the network resource which you want to connect to, for example, “\\server_name\share_name”.

Note that the parameter's value can also contain values in any of the following formats: IPv4 address (for example, "\\192.168.1.1\share") and IPv6 address (for example, "\\2001-4898-9-3-c069-aa97-fe76-2449.ipv6-literal.net\share").

User

Specifies the user account you want to use to create the connection. If the parameter is not specified, the current user account is used to create the connection.

Password

Specifies the password you want to use to create the connection. If the parameter is not specified, the method uses the default password of the user account specified by the user parameter.

Remember

Specifies whether TestComplete will establish a connection to the specified network drive automatically next time you log in to the system under the current user account.

Result Value

If the connection is created successfully, the method returns zero. Otherwise, the method returns an error code. To get the description that corresponds to the given code, you can use the aqUtils.SysErrorMessage method. The complete list of error codes is provided in the System Error Codes article in the MSDN library.

Example

The following code snippet establishes connection to the \\Tester\WorkDirectory network folder and redirects the “Z:” local device to this folder.

JavaScript, JScript

function Connect()
{
  var local_name, path, user_name, password, res;
  // Specifies the name of the local device to be redirected to
  local_name = "Z:";
  // Specifies the network folder to connect to
  path = "\\\\Tester\\WorkDirectory";
  // Specifies the user account to connect
  user_name = "Tester";
  // Specifies the user account password
  password = "password";

  // Connects to the network folder
  res = aqFileSystem.MapNetworkDrive(local_name, path, user_name, password);
  if (res != 0)
    Log.Error(aqUtils.SysErrorMessage(res) + " Error code is " + res + ".");
  else
    Log.Message("The connection to '" + path + "' has been established successfully.");
}

Python

def Connect():
  # Specifies the name of the local device to be redirected to
  local_name = "Z:"
  # Specifies the network folder to connect to
  path = "\\\\Tester\\WorkDirectory"
  # Specifies the user account to connect
  user_name = "Tester"
  # Specifies the user account password
  password = "password"
  # Connects to the network folder
  res = aqFileSystem.MapNetworkDrive(local_name, path, user_name, password)
  if res != 0:
    Log.Error(aqUtils.SysErrorMessage(res) + " Error code is " + str(res) + ".")
  else:
    Log.Message("The connection to '" + path + "' has been established successfully.")

VBScript

Sub Connect
Dim local_name, path, user_name, password, res

  ' Specifies the name of the local device to be redirected to
  local_name = "Z:"
  ' Specifies the network folder to connect to
  path = "\\Tester\WorkDirectory"
  ' Specifies the user account to connect
  user_name = "Tester"
  ' Specifies the user account password
  password = "password"

  ' Connects to the network folder
  res = aqFileSystem.MapNetworkDrive(local_name, path, user_name, password)
  If res <> 0 Then
    Log.Error(aqUtils.SysErrorMessage(res) & " Error code is " & res & ".")
  Else
    Log.Message("The connection to '" & path & "' has been established successfully.")
  End If

End Sub

DelphiScript

procedure Connect();
var local_name, path, user_name, password, res;
begin
  // Specifies the name of the local device to be redirected to
  local_name := 'Z:';
  // Specifies the network folder to connect to
  path := '\\Tester\WorkDirectory';
  // Specifies the user account to connect
  user_name := 'Tester';
  // Specifies the user account password
  password := 'password';

  // Connects to the network folder
  res := aqFileSystem.MapNetworkDrive(local_name, path, user_name, password);
  if res <> 0 then
    Log.Error(aqUtils.SysErrorMessage(res) + ' Error code is ' + res + '.')
  else
    Log.Message('The connection to ''' + path + ''' has been established successfully.');
end;

C++Script, C#Script

function Connect()
{
  var local_name, path, user_name, password, res;
  // Specifies the name of the local device to be redirected to
  local_name = "Z:";
  // Specifies the network folder to connect to
  path = "\\\\Tester\\WorkDirectory";
  // Specifies the user account to connect
  user_name = "Tester";
  // Specifies the user account password
  password = "password";

  // Connects to the network folder
  res = aqFileSystem["MapNetworkDrive"](local_name, path, user_name, password);
  if (res != 0)
    Log["Error"](aqUtils["SysErrorMessage"](res) + " Error code is " + res + ".");
  else
    Log["Message"]("The connection to '" + path + "' has been established successfully.");
}

See Also

DisconnectNetworkDrive Method
aqFileSystem Object
Drives Property
aqFolderInfo Object
SysErrorMessage Method

Highlight search results