subst

subst is a command on the DOS, IBM OS/2 and Microsoft Windows operating systems used for substituting paths on physical and logical drives as virtual drives. In the past it has been used for revealing hidden drives on security-tense PCs.

The Windows subst command is available in Windows 2000 SP4 or later versions of the command line interpreter cmd.exe.[1]

In Windows NT, subst uses DefineDosDevice() to create the disk mappings.

Some versions of MS-DOS COMMAND.COM support the undocumented internal truename command which can display the "true name" of a file, by bypassing subst and assign filesystem mappings.

Contents

Usage

This is the Command Prompt output under Windows XP:

C:\>subst /?
Associates a path with a drive letter.

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

  drive1:        Specifies a virtual drive to which you want to assign a path.
  [drive2:]path  Specifies a physical drive and path you want to assign to
                 a virtual drive.
  /D             Deletes a substituted (virtual) drive.

Type SUBST with no parameters to display a list of current virtual drives.

This means that, for example, to map C:'s root to X: one would use subst X: C:\ at the command line. Upon doing this, a new drive called X: would appear under the My Computer Virtual Folder in Windows Explorer.

To unmap the drive, type in the following command at the command prompt:

C:\>subst [drive:] /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 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.

Persisting across reboots

Drive letters mapped in this way are not available during system startup for services nor do they persist across a reboot. However with a registry modification it is possible to assign a path to a drive letter during startup so it is available to system services and persists across a reboot.

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 the form: \??\C:\some\directory
or in form: \DosDevices\C:\some\directory
or in form: \Device\Mup\127.0.0.1\C$\some\directory

There are tools available to make the necessary changes for you.

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)

Limitations

See also

References

External links