SUBST

Last updated
subst
Developer(s) Microsoft, IBM, Digital Research, ReactOS Contributors
Initial release1985, 3738 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.microsoft.com/en-us/windows-server/administration/windows-commands/subst

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.

Contents

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 SUBST 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 DefineDosDevice() to create the disk mappings.

The 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 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[ 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 press F2 ) 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.

In addition the LABEL command is able to change the label name

LABEL <Your Drive Letter>: "Your label value"

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 psubst.

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 off SUBST f: d:\mount\db SUBST g: d:\mount\log 

The 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 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.

Limitations

See also

Related Research Articles

<span class="mw-page-title-main">Drive letter assignment</span> Alphabetical assignment to logical drives on computers (e.g., C:\)

In computer data storage, drive letter assignment is the process of assigning alphabetical identifiers to volumes. Unlike the concept of UNIX mount points, where volumes are named and located arbitrarily in a single hierarchical namespace, drive letter assignment allows multiple highest-level namespaces. Drive letter assignment is thus a process of using letters to name the roots of the "forest" representing the file system; each volume holds an independent "tree".

<span class="mw-page-title-main">COMMAND.COM</span> Default command line for MS-DOS and Windows 9x

COMMAND.COM is the default command-line interpreter for MS-DOS, Windows 95, Windows 98 and Windows Me. In the case of DOS, it is the default user interface as well. It has an additional role as the usual first program run after boot, hence being responsible for setting up the system by running the AUTOEXEC.BAT configuration file, and being the ancestor of all processes.

In computing, a symbolic link is a file whose purpose is to point to a file or directory by specifying a path thereto.

<span class="mw-page-title-main">Windows 9x</span> Series of Microsoft Windows computer operating systems

Windows 9x is a generic term referring to a series of Microsoft Windows computer operating systems produced from 1995 to 2000, which were based on the Windows 95 kernel and its underlying foundation of MS-DOS, both of which were updated in subsequent versions. The first version in the 9x series was Windows 95, which was succeeded by Windows 98 and then Windows Me, which was the third and last version of Windows on the 9x line, until the series was superseded by Windows XP.

<span class="mw-page-title-main">Windows Registry</span> Database for Microsoft Windows

The Windows Registry is a hierarchical database that stores low-level settings for the Microsoft Windows operating system and for applications that opt to use the registry. The kernel, device drivers, services, Security Accounts Manager, and user interfaces can all use the registry. The registry also allows access to counters for profiling system performance.

AutoRun and the companion feature AutoPlay are components of the Microsoft Windows operating system that dictate what actions the system takes when a drive is mounted.

AutoPlay, a feature introduced in Windows 98, examines newly discovered removable media and devices and, based on content such as pictures, music or video files, launches an appropriate application to play or display the content. It is closely related to the AutoRun operating system feature. AutoPlay was created in order to simplify the use of peripheral devices – MP3 players, memory cards, USB storage devices and others – by automatically starting the software needed to access and view the content on these devices. AutoPlay can be enhanced by AutoPlay-compatible software and hardware. It can be configured by the user to associate favourite applications with AutoPlay events and actions.

In computer data storage, a volume or logical drive is a single accessible storage area with a single file system, typically resident on a single partition of a hard disk. Although a volume might be different from a physical disk drive, it can still be accessed with an operating system's logical interface. However, a volume differs from a partition.

The booting process of Windows NT is the process run to start Windows NT. The process has been changed between releases, with the biggest changes being made with Windows Vista. In versions before Vista, the booting process begins when the BIOS loads the Windows NT bootloader, NTLDR. Starting with Vista, the booting process begins with either the BIOS or UEFI load the Windows Boot Manager, which replaces NTLDR as the bootloader. Next, the bootloader starts the kernel, which starts the session manager, which begins the login process. Once the user is logged in, File Explorer, the graphical user interface used by Windows NT, is started.

Drive mapping is how MS-DOS and Microsoft Windows associate a local drive letter with a shared storage area to another computer over a network. After a drive has been mapped, a software application on a client's computer can read and write files from the shared storage area by accessing that drive, just as if that drive represented a local physical hard disk drive.

The Session Manager Subsystem, or smss.exe, is a component of the Microsoft Windows NT family of operating systems, starting in Windows NT 3.1. It is executed during the startup process of those operating systems.

The NTFS file system defines various ways to redirect files and folders, e.g., to make a file point to another file or its contents without making a copy of it. The object being pointed to is called the target. Such file is called a hard or symbolic link depending on a way it's stored on the filesystem.

Contig is a command line defragmentation utility for Windows developed by Microsoft as part of the Sysinternals Suite.

The booting process of Microsoft Windows varies between different releases.

NTBackup is the built-in backup application introduced in Windows NT 3.51 and included in Windows NT 4.0, Windows 2000, Windows XP, and Windows Server 2003. NTBackup comprises a command-line utility and a set of wizard interfaces that provide multiple options to create, customize, and manage backups, and it is integrated with Shadow Copy and Task Scheduler. NTBackup creates backups in a proprietary BKF file format to external sources including floppy disks, hard drives, tape drives, and ZIP drives.

<span class="mw-page-title-main">Trash (computing)</span> Temporary storage for deleted files

In computing, the trash, also known by other names such as dustbin, wastebasket, and others, is a graphical user interface desktop metaphor for temporary storage for files set aside by the user for deletion, but not yet permanently erased. The concept and name is part of Mac operating systems, a similar implementation is called the Recycle Bin in Microsoft Windows, and other operating systems use other names.

A batch file is a script file in DOS, OS/2 and Microsoft Windows. It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. A batch file may contain any command the interpreter accepts interactively and use constructs that enable conditional branching and looping within the batch file, such as IF, FOR, and GOTO labels. The term "batch" is from batch processing, meaning "non-interactive execution", though a batch file might not process a batch of multiple data.

In computing, label is a command included with some operating systems. It is used to create, change, or delete a volume label on a logical drive, such as a hard disk partition or a floppy disk. Used without parameters, label changes the current volume label or deletes the existing label.

<span class="mw-page-title-main">Architecture of Windows 9x</span>

The Windows 9x series of operating systems refers to the kernel which lies at the heart of Windows 9x. Its architecture is monolithic.

Service Control Manager (SCM) is a special system process under the Windows NT family of operating systems, which starts, stops and interacts with Windows service processes. It is located in the %SystemRoot%\System32\services.exe executable. Service processes interact with SCM through a well-defined API, and the same API is used internally by the interactive Windows service management tools such as the MMC snap-in Services.msc and the command-line Service Control utility sc.exe. Terminating this file is used as a method of causing the Blue Screen of Death.

References

  1. "JaTomes Help - OS/2 Commands". www.jatomes.com. Archived from the original on 2019-04-14.
  2. "Reactos/Reactos". GitHub . 22 November 2021.
  3. Wolverton, Van (2003). Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition. Microsoft Press. ISBN   0-7356-1812-7.
  4. DR DOS 6.0 User Guide Optimisation and Configuration Tips
  5. "FreeDOS 1.2 Updates Group - FreeDOS Base". Ibiblio.org. Retrieved 2022-09-04.
  6. "PTS-DOS 2000 Pro User Manual" (PDF). Buggingen, Germany: Paragon Technology GmbH. 1999. Archived (PDF) from the original on 2018-05-12. Retrieved 2018-05-12.
  7. "Subst". learn.microsoft.com. 11 September 2009.
  8. "Microsoft.com". Microsoft .
  9. "Windows - How to make SUBST mapping persistent across reboots?".

Further reading