SUBST explained

subst
Developer:Microsoft, IBM, Digital Research, ReactOS Contributors
Operating System:MS-DOS, PC DOS, SISNE plus, OS/2, eComStation, ArcaOS, DR DOS, ROM-DOS, PTS-DOS, FreeDOS, Windows, ReactOS
Platform:Cross-platform
Genre:Command

In computing, SUBST is a command on the DOS, IBM OS/2,[1] Microsoft Windows and ReactOS[2] operating systems used for substituting paths on physical and logical drives as virtual drives.

Overview

In MS-DOS, the SUBST command was added with the release of MS-DOS 3.1.[3] The command is similar to floating drives, a more general concept in operating systems of Digital Research origin, including CP/M-86 2.x, Personal CP/M-86 2.x, Concurrent DOS, Multiuser DOS, System Manager 7, REAL/32, as well as DOS Plus and DR DOS (up to 6.0). DR DOS 6.0 includes an implementation of the command.[4] The command is also available in FreeDOS[5] and PTS-DOS.[6] The Windows SUBST command is available in supported versions of the command line interpreter cmd.exe.[7] In Windows NT, SUBST uses [http://msdn.microsoft.com/en-us/library/aa363904%28VS.85%29.aspx DefineDosDevice] to create the disk mappings.

The [[JOIN (command)|JOIN]] command is the "opposite" of SUBST, because JOIN will take a drive letter and make it appear as a directory.

Some versions of MS-DOS [[COMMAND.COM]] support the undocumented internal [[TRUENAME]] command which can display the "true name" of a file, i.e. the fully qualified name with drive, path, and extension, which is found possibly by name only via the PATH environment variable, or through SUBST, JOIN and [[ASSIGN (DOS command)|ASSIGN]] filesystem mappings.

Syntax

This is the command syntax in Windows XP to associate a path with a drive letter:

SUBST [drive1: [drive2:]path] SUBST drive1: /D

Parameters

Examples

Mapping a drive

This means that, for example, to map C:'s root to X:, the following command would be used at the command-line interface:

C:\>SUBST X: C:\

Upon doing this, a new drive called X: would appear under the My Computer virtual folder in Windows Explorer.

Unmapping a drive

To unmap drive X: again, the following command needs to by typed at the command prompt:

C:\>SUBST X: /D

Custom label

A custom label can be assigned to a drive letter created in this way by way of a registry key, which can be created by renaming (select "rename" from the drive letter context menu or press) the SUBST drive in Windows Explorer/My Computer.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\M\DefaultLabel\ (DefaultValue) = ''Your Drive Label''

"M" represents the drive letter to assign a custom label to.

However, labels created for SUBST drives in this manner are overridden by the label of the host drive/partition: the custom labels are only used if the host drive has no label. One may then:

  1. Delete the host's drive label;
  2. Create the proper registry keys for the SUBST drive letter;
  3. Create the proper registry keys for the host drive letter (optional, works around the host drive label override caveat);
  4. Re-create the SUBST drive to see label changes applied.

Note that the LABEL command is NOT able to change the label name of a drive letter created using subst.[8] LABEL is one of several commands that only work on physical drives.[9]

Persisting across reboots

Drive letters mapped with the command are not available during system startup for services nor do they persist across a reboot.

Registry (DOS Devices)

The DOS Devices mechanism that underlies subst can be set in registry. This way, the mapped drives are usable immediately during startup.

Create a new registry entry "String Value" in the following key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices

The name should be  "X:"  where X is the drive letter.

The value should be the path in one of the following NT Object Manager forms:

There are tools available to make the necessary changes for the user, including .

The relative to this thematic registry key is HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices. It defines mapping of drive letters into particular hard disk partitions, similar to /etc/fstab on a Unix system. It also can be edited manually, but only at that time while that particular installed Window operation system is "inactive". So that, for example, if you currently boot from "D:\Windows" then you can edit the HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices key of Windows that is installed in a "C:\Windows" folder, for an instance by doing the following actions:

  1. run command: reg load hklm\$system C:\WINDOWS\system32\config\system
  2. run command: regedit.exe
  3. edit registry key HKEY_LOCAL_MACHINE\$system\MountedDevices
    (that represents the HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices registry key of the Windows instance that is installed in C:\WINDOWS)
  4. close regedit.exe
  5. run command: reg unload hklm\$system (to complete the editing procedure)

Importing reg file

The easiest way to do this is to create a registry file (.reg), and double click the file to import the settings into the registry.

Here is an example registry file.REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices]"F:"="\\??\\D:\\Mount\\db""G:"="\\??\\D:\\Mount\\log"

After configuring the registry the computer must be rebooted for the changes to take effect.

Run on boot (batch)

Create a batch file to run the built-in SUBST command to create a virtual drive letter for the existing mount points and place it in the user accounts startup folder.

This is not preferred, as the mapping only appears at the end of user logon.

Here is an example:
@ECHO offSUBST f: d:\mount\dbSUBST g: d:\mount\logThe user must log off and back on or the service must be restarted for the changes to take effect.

Run on boot (registry)

Edit the registry to run the built-in subst command during computer startup or user logon by leveraging the appropriate Run registry key. The easiest way to do this is to create a registry file (.reg), and double click the file to import the settings into the registry. This is not preferred, as the mapping only appears at the end of bootup.

Example to run during computer bootREGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]"F Drive"="SUBST f: d:\\mount\\db""G Drive"="SUBST g: d:\\mount\\log" The computer must be rebooted for the changes to take effect. Example of user logonREGEDIT4

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]"F Drive"="SUBST f: d:\\mount\\db""G Drive"="SUBST g: d:\\mount\\log"

The user must log off and back on for the changes to take effect.

Limitations

See also

Further reading

External links

Notes and References

  1. Web site: JaTomes Help - OS/2 Commands . www.jatomes.com . dead . https://web.archive.org/web/20190414130029/http://www.jatomes.com/Help/Os2Cmd.php . 2019-04-14.
  2. Web site: Reactos/Reactos. GitHub. 22 November 2021.
  3. Book: Wolverton. Van. Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition. 2003. Microsoft Press. 0-7356-1812-7.
  4. https://www.4corn.co.uk/archive/docs/DR%20DOS%206.0%20User%20Guide-opt.pdf DR DOS 6.0 User Guide Optimisation and Configuration Tips
  5. Web site: FreeDOS 1.2 Updates Group - FreeDOS Base . Ibiblio.org . 2022-09-04.
  6. Web site: PTS-DOS 2000 Pro User Manual . . Buggingen, Germany . 1999 . 2018-05-12 . live . https://web.archive.org/web/20180512094512/http://download.paragon-software.com/doc/manual_dos_eng.pdf . 2018-05-12.
  7. Web site: Subst. learn.microsoft.com. 11 September 2009 .
  8. https://superuser.com/a/198509/557294
  9. https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/subst
  10. Web site: Microsoft.com. .
  11. Web site: Windows - How to make SUBST mapping persistent across reboots?.