SUBST
| Company type | Command |
|---|---|
| Industry | Computing / Operating systems |
| Founded | 1984 |
| Products | Virtual drive assignment command |
In computing, the SUBST command is utilized within DOS, IBM OS/2, Microsoft Windows, and ReactOS environments to assign physical or logical drive paths as virtual drives.
Overview
The SUBST command made its debut in MS-DOS version 3.1. It shares similarities with the floating drive feature present in operating systems derived from Digital Research, such as various editions of CP/M-86, Concurrent DOS, Multiuser DOS, and System Manager 7. Additionally, SUBST is implemented in DR DOS 6.0 and is supported by other DOS variants including FreeDOS and PTS-DOS. On Windows platforms, the command operates through the command-line interpreter (cmd.exe) and leverages the DefineDosDevice() API on Windows NT systems to establish virtual disk associations.
The <a href="JOIN_(command)">JOIN</a> command acts as a counterpart to SUBST, enabling the conversion of a drive letter back into its corresponding directory path.
Certain MS-DOS versions of COMMAND.COM incorporate an undocumented internal command named TRUENAME, which reveals the absolute path of files by resolving mappings created by commands such as SUBST, JOIN, and ASSIGN.
Syntax
On Windows XP, the syntax for linking a directory path to a drive letter is as follows:
SUBST [drive1: [drive2:]path] SUBST drive1: /D
Parameters
drive1:– The designated virtual drive letter for the substitution.[drive2:]path– The actual physical drive and directory path to be assigned./D– Removes an existing substituted (virtual) drive.
Assigning a virtual drive
To map the root directory of C: to the drive letter X:, execute this command at the command-line interface:
<syntaxhighlight lang="doscon"> C:\>SUBST X: C:\ </syntaxhighlight>
This action generates a new drive X:, which appears under virtual folders in My Computer within Windows Explorer.
Removing a virtual drive
To delete the mapping for X:, use:
<syntaxhighlight lang="doscon"> C:\>SUBST X: /D </syntaxhighlight>
Custom labeling
It is possible to assign personalized labels to SUBST drives by modifying registry keys, typically created when renaming the substituted drive through Windows Explorer or My Computer:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\M\DefaultLabel\
(DefaultValue) = Your Drive Label
(where "M" represents the substituted drive letter)
These custom labels will be overridden if the original host drive has an existing label; they only display when the host lacks one. For effective custom labeling, users must clear the host’s label, create suitable registry entries for both the SUBST and host drives, and then re-establish the substituted drive.
Note that the LABEL command does not affect labels on SUBST drives—it functions exclusively on physical drives.
Persistence after reboot
Mappings created with SUBST do not survive system restarts and are unavailable during early startup phases for services.
Registry configuration (DOS Devices)
To retain substituted drives after reboot, add a new "String Value" entry under:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices
Name this entry "X:" (with X representing the desired drive letter), assigning it one of these NT Object Manager paths as its value:
\??\C:\some\directory(recommended)\DosDevices\C:\some\directory\Device\Mup\127.0.0.1\C$\some\directory(less optimal due to SMB protocol overhead)
Various utilities exist to automate these registry modifications.
A related registry key, HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices, provides mappings between drive letters and physical partitions, functioning similarly to Unix’s /etc/fstab. Editing this key requires offline access to the target Windows system by loading its registry hive with commands like:
reg load hklm\$system C:\WINDOWS\system32\config\systemregedit.exe, then modifyHKEY_LOCAL_MACHINE\$system\MountedDevices- Unload hive afterward via
reg unload hklm\$system
This approach allows manual adjustment of drive-letter assignments for Windows installations that are not currently active.
Importing a registry file
The most straightforward approach involves generating a registry file (.reg) and executing it via double-click to insert the settings into the Windows registry.
Sample registry file: <syntaxhighlight lang="registry"> REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices] "F:"="\\??\\D:\\Mount\\db" "G:"="\\??\\D:\\Mount\\log" </syntaxhighlight>
A system restart is necessary for these modifications to become active.
Executing at startup using a batch file
You can create a batch script utilizing the native SUBST command to assign virtual drive letters when the user logs in. This script should be placed in the user's startup directory.
Example: <syntaxhighlight lang="dosbatch"> @ECHO off SUBST f: d:\mount\db SUBST g: d:\mount\log </syntaxhighlight>
This technique is generally less desirable because the mappings are established only after user login. Users must either log out and log back in or reboot the system for the changes to take effect.
Executing at startup via registry
By setting up the registry to launch SUBST commands at system boot or user login through the Run key, you can automate drive letter assignments. Importing a .reg file is the most convenient method.
Example for system startup: <syntaxhighlight lang="registry"> REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] "F Drive"="SUBST f: d:\\mount\\db" "G Drive"="SUBST g: d:\\mount\\log" </syntaxhighlight>
A reboot is required to apply these changes.
Example for user login: <syntaxhighlight lang="registry"> REGEDIT4
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] "F Drive"="SUBST f: d:\\mount\\db" "G Drive"="SUBST g: d:\\mount\\log" </syntaxhighlight>
Users need to log off and log back in for the settings to take effect.
Limitations
- Operations targeting physical disks are not supported on substituted drives.
- Since Windows XP Service Pack 2,
autorun.inffiles located on substituted drives are ignored; hence, AutoRun/AutoPlay features and custom icons or labels defined byautorun.infwill not function. Custom volume labels only appear if the original volume lacks one. - Starting with Windows Vista, files deleted from substituted drives bypass the Recycle Bin and are removed permanently; earlier Windows versions redirected such deletions to the Recycle Bin. A registry modification can restore Recycle Bin behavior.
- Permissions on substituted drives may differ from those on original volumes, potentially causing problems such as unsuccessful software installations or inability to write log files, even with administrative rights.
See also
Further reading
External links
- Microsoft Docs: subst
- SS64.com: subst command
- psubst: persistent drive mapping tool
- Visual Subst — GUI application for persistent drive mapping