The command: "SUBST" is on Windows 12, 11, 10, .. , MS Server 2025, 2022, 2019, .. available
The examples for the command "SUBST"
The
`SUBST` command in the Windows Command Prompt is used to assign a virtual drive letter to a path. Here are some examples of using the
`SUBST` command:
Example 1: Assigning a virtual drive letter:
SUBST X: C:\MyFolder
Description: This example assigns the path
`C:\MyFolder` to the
`X:` drive. You can now access the
`C:\MyFolder` directory via the virtual drive
`X:`.
Example 2: View all mapped virtual disks:
SUBST
Description: If you call
`SUBST` without arguments, it will display all currently mapped virtual drives.
Example 3: Unmapping a virtual disk:
SUBST X: /D
Description: This command unmaps the virtual disk
`X:`.
Example 4: Using Environment Variables:
SET MyFolder=C:\Users\YourUsername\My Documents
SUBST Y: %MyFolder%
Description: Here an environment variable (
`MyFolder`) is created and then assigned to the drive
`Y:`. This can be useful if you want to use variable paths in a script.
Example 5: Using relative paths:
CD\Projects
SUBST P: .
Description: The
`SUBST P: .` command assigns the current directory (
`.`) as the path to the
`P:` drive. This allows you to access the current directory via the virtual drive
`P:`.
However, there are a few things to keep in mind:
- Virtual drives created with
`SUBST` are only valid for the current session and are lost after a reboot.
- Deleting a virtual drive is done with
`/D`.
- Make sure that the assigned drive letters are not already in use by another drive.
- If you use
`SUBST` in a script or batch file, note that the virtual drive mapping is only valid within the execution of the script and is deallocated when the script exits.
It is important to note that virtual disks created with
`SUBST` are not persistent and will be released after a system reboot. If you want persistent associations, you should use
`NET USE` or the Windows Registry instead.
"SUBST" Excerpt from Microsoft Windows Help
Microsoft Windows [Version 10.0.19045.3693]
(c) Copyright 1985-2023 Microsoft Corp.
C:\\WINDOWS>
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.
Important information, tips for the "SUBST" command
There are a few important points to note when using the
`SUBST` command in the Windows Command Prompt:
1.
Mapping Persistence: The virtual drives created with
`SUBST` are only valid for the current session and will be lost after a system reboot. If you need persistent associations, you should use
`NET USE` or the Windows Registry instead.
2.
Caution when selecting drive letter: Make sure that the assigned drive letter is not already in use by another drive or device. Selecting drive letters should be avoided if physical drives or network shares already use that letter.
3.
Unmap: To unmap a virtual disk, use the
`SUBST` command with the
`/D` switch.
SUBST X: /D
4.
Use of environment variables: You can use environment variables to make paths more flexible. However, note that these environment variables are only valid in the current session.
SET MyFolder=C:\Users\YourUsername\My Documents
SUBST Y: %MyFolder%
5.
Relative Paths: `SUBST` also allows the use of relative paths. You can use the current directory as the virtual drive path.
CD\Projects
SUBST P: .
It is important to note that
`SUBST` tends to only provide temporary, session-based mappings. If you want persistent associations, especially after a system reboot, it may be better to resort to other mechanisms such as: E.g.
`NET USE` for network drives or the Windows registry for permanent drive letter assignments.