This articlecontainsinstructions or advice. Wikipedia is not a guidebook; please helprewrite such content to be encyclopedic or move it toWikiversity,Wikibooks, orWikivoyage.(January 2021) |
| subst | |
|---|---|
| Developers | Microsoft,IBM,Digital Research, ReactOS Contributors |
| Initial release | 1985, 39–40 years ago |
| Operating system | MS-DOS,PC DOS,SISNE plus,OS/2,eComStation,ArcaOS,DR DOS,ROM-DOS,PTS-DOS,FreeDOS,Windows,ReactOS |
| Platform | Cross-platform |
| Type | Command |
| Website | docs |
Incomputing,SUBST is acommand on theDOS,IBMOS/2,[1]Microsoft Windows andReactOS[2]operating systems used for substitutingpaths on physical and logical drives asvirtual drives.
InMS-DOS, theSUBST command was added with the release of MS-DOS 3.1.[3] The command is similar tofloating drives, a more general concept in operating systems ofDigital Research origin, includingCP/M-86 2.x,Personal CP/M-86 2.x,Concurrent DOS,Multiuser DOS,System Manager 7,REAL/32, as well asDOS Plus andDR DOS (up to 6.0).DR DOS 6.0 includes an implementation of theSUBST command.[4] The command is also available inFreeDOS[5] andPTS-DOS.[6] The WindowsSUBST command is available in supported versions of thecommand line interpretercmd.exe.[7] InWindows NT,SUBST usesDefineDosDevice() to create the disk mappings.
TheJOIN command is the "opposite" ofSUBST, becauseJOIN will take a drive letter and make it appear as a directory.
Some versions ofMS-DOSCOMMAND.COM support the undocumented internalTRUENAME 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 thePATH environment variable, or throughSUBST,JOIN andASSIGN filesystem mappings.
This is the command syntax inWindows XP to associate a path with a drive letter:
SUBST [drive1: [drive2:]path]SUBST drive1: /D
drive1: – Specify a virtual drive to which to assign a path.[drive2:]path – Specify a physical drive and path to assign to a virtual drive./D – Delete a substituted (virtual) drive.This means that, for example, to map C:'s root to X:, the following command would be used at thecommand-line interface:
C:\>SUBST X: C:\Upon doing this, a new drive called X: would appear under theMy Computervirtual folder inWindows Explorer.
To unmap drive X: again, the following command needs to by typed at the command prompt:
C:\>SUBST X: /DA custom label can[citation needed] 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 pressF2) 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:
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]
Drive letters mapped with the command are not available during system startup for services nor do they persist across a reboot.
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 DevicesThe name should be "X:" whereX is the drive letter.
The value should be the path in one of the followingNT Object Manager forms:
\??\C:\some\directory (preferred)\DosDevices\C:\some\directory (long version of the former)\Device\Mup\127.0.0.1\C$\some\directory (discouraged, as this goes through SMB share)There are tools available to make the necessary changes for the user, includingpsubst.
The relative to this thematic registry key isHKEY_LOCAL_MACHINE\SYSTEM\MountedDevices. It defines mapping of drive letters into particular hard disk partitions, similar to/etc/fstab on aUnix 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 theHKEY_LOCAL_MACHINE\SYSTEM\MountedDevices key of Windows that is installed in a "C:\Windows" folder, for an instance by doing the following actions:
reg load hklm\$system C:\WINDOWS\system32\config\systemregedit.exeHKEY_LOCAL_MACHINE\$system\MountedDevicesHKEY_LOCAL_MACHINE\SYSTEM\MountedDevices registry key of the Windows instance that is installed inC:\WINDOWS)regedit.exereg unload hklm\$system (to complete the editing procedure)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.
Create a batch file to run the built-inSUBST 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\log
The user must log off and back on or the service must be restarted for the changes to take effect.
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 boot
REGEDIT4[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 logon
REGEDIT4[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.
autorun.inf files present in the new drive letter are ignored; thus,AutoRun/AutoPlay does not work on drive letters created in this way. In addition, assigning a custom icon or label to the drive letter created this way viaautorun.inf does not work. A custom label assigned to the drive letter created withsubst only appears if the source drive/volume does not have a volume label set (check and set with thelabel command).