Connecting Hard Disk of External PC (shared folder)

Other topics about Application Programs

Overview

The map_drive.vba shows a sample program (VBA program) that demonstrates how to connect a hard disk (a shared folder) of an external PC to the E5061B.  This VBA program consists of the following modules:

Object name

Module type

Description

frmMapDrive

User form

Connects or disconnects a hard disk

Module1

Standard module

Displays frmMapDrive

Using VBA Program

Load the map_drive.vba and press Macro Run key. The following macro appears.

Shared folder connection macro

Connecting (Mapping)

Enter the drive letter for the shared folder (1), share name of the shared folder (2), user name (3), password (4), and then click Map (5).

Disconnecting

  1. Enter the drive letter for the shared folder (1), and then click Disconnect (6).

  2.   Click Exit (7) to exit from the program.

 

Description of VBA Program

The program (object name: frmMapDrive) is described in detail below. The following description is included as a comment in the source code.

Sub CommandButton1_Click

This procedure is called when the user clicks the Map button. It checks whether the drive letter is used by using the IsDriveNameInUse procedure. Then the procedure connects the shared folder using the MapDrive procedure if the drive letter is not used or otherwise it displays a message to show the drive in use.

Sub CommandButton2_Click

This procedure is called when the user clicks the Disconnect button. The procedure disconnects the shared folder by using the DisconnectDrive procedure.

Function IsDriveNameInUse

This procedure checks if the txtDrive.Text (the drive letter specified by 1)  is used.

Sub MapDrive

This procedure connects the shared folder as the txtDrive.Text (the drive letter specified by 1) drive by using the parameters: txtShare.Text (the share name specified by 2), txtUser.Text (the user name specified by 3), and txtPasswd.Text (the password specified by 4).

Sub DisconnectDrive

This procedure disconnects the txtDrive.Text (the drive letter specified by 1) drive.

Sub CommandButton3_Click

This procedure is called when the user clicks the Exit button. This procedure ends the program.

 

 Connecting the hard disk of an external PC (Object name: frmMapDrive)

'

' This procedure is called when the user clicks the Map button. It checks whether

' the drive letter is used by using the IsDriveNameInUse procedure.

' Then the procedure connects the shared folder using the MapDrive procedure

' if the drive letter is not used or otherwise displays a message to show

' the drive letter is used.

'

Private Sub CommandButton1_Click()

  If Not IsDriveNameInUse Then

    Call MapDrive

  Else

    MsgBox "Drive """ & txtDrive.Text & """ is Already used", vb Critical

  End If

End Sub

'

' This procedure is called when the user clicks the Disconnect button.

' The procedure disconnects the shared folder by using the DisconnectDrive procedure.

'

Private Sub CommandButton2_Click()

  Call DisconnectDrive

End Sub

'

' This procedure checks if the txtDrive.Text is used.

'

Private Function IsDriveNameInUse() As Boolean

  Set fso = CreateObject("Scripting.FileSystemObject")

  IsDriveNameInUse = fso.DriveExists(txtDrive.Text)

End Function

'

' This procedure connects the shared folder as the txtDrive.Text drive by using the parameters:

' txtShare.Text, txtUser.Text, and txtPasswd.Text.

'

Private Sub MapDrive()

  Set network = CreateObject("wscript.network")

  Call network.MapNetworkDrive(txtDrive.Text, txtShare.Text, vbFal se, txtUser.Text, txtPasswd.Text)

End Sub

'

' This procedure disconnects the txtDrive.Text drive.

'

Private Sub DisconnectDrive()

  Set network = CreateObject("wscript.network")

  network.RemoveNetworkDrive txtDrive.Text

End Sub

'

' This procedure is called when the user clicks the Exit button. This procedure ends the program.

'

Private Sub CommandButton3_Click()

  Unload Me

End Sub