3.6 Network Drives

A program can access the files and directories on a network drive by connecting to the drive using Make Network Connection (Interrupt 21h Function 5F03h). This function associates a drive name with the network drive, permitting the program to use the network drive as a logical drive. A program can connect to a network drive only if the network is running. To determine whether the network is running, a program can use Get Machine Name (Interrupt 21h Function 5E00h). This function returns an error value if the network is not running.

To connect to a network drive, a program must supply the drive's network name, which consists of a computer name and a share name. The computer name uniquely identifies the network server owning the drive, and the share name identifies the drive. A program creates a network name by combining the computer and share names as a zero-terminated ASCII string with the form shown in the following example:

NetworkDrive DB '\\SERVER\FILES',0

If the network drive is password-protected, the program must supply the password, as shown in the following example:

NetworkDrive DB '\\SERVER\FILES',0,'PaSsWoRd',0

The drive name the program provides must be the name of one of the available drives identified by using Set Default Drive (Interrupt 21h Function 0Eh). If the specified drive is valid (that is, if it has a corresponding physical drive), the physical drive is temporarily inaccessible while the drive name is associated with the network drive.

After a network connection is made, a program can use functions such as Get Disk Free Space (Interrupt 21h Function 36h) to retrieve information about the network drive, and it can open or create files and directories on the network drive, as long as the network grants read-and-write permission.

Once a program connects to a network drive, the connection is a global resource until the drive is explicitly disconnected. A program can check for existing network connections by using Is Drive Remote (Interrupt 21h Function 4409h). This function sets bit 12 in the DX register if a logical drive is associated with a network drive. A program can retrieve the drive's network name by using Get Assign-List Entry (Interrupt 21h Function 5F02h).

A program can disconnect from a network drive by using Delete Network Connection (Interrupt 21h Function 5F04h) to remove any association between the drive name and the network drive. In general, a program should close and disconnect from any network device it no longer needs.

Some network software may provide other means to connect and disconnect network drives. For more information about network connections, see the applicable network documentation.