106

Is there a windows equivalent to the old dos SUBST command?

I want to be able to assign a local drive letter to a folder on a local drive.

I realize that a mapped drive will work (and so far that's the technique I've ended up using), but it doesn't seem to cut-in until rather late in the boot process. I've also in the past tried putting SUBST commands in batch files in the boot process, but that doesn't seem to work either.

1

6 Answers 6

97

Good news! The subst command still works in Windows 7!

To create a new mapping:

subst x: C:\Folder\Example

To remove a mapping:

subst x: /D

5
  • 2
    Yes, I know it works, but I couldn't get it to happen automagically on boot (especially as early as possible). Do you know how that can be done? Sep 13, 2013 at 4:47
  • 1
    Have you tried making a batch file out of the above command and adding that as a startup script in gpedit.msc/Local Group Policy Editor?
    – Josh
    Sep 13, 2013 at 4:54
  • Have now... I don't think I tracked that down (not being a sysadmin) when I tried it before. Seems to be the place to do it... However, using @50-3's point I may use NET USE in place of SUBST. Sep 13, 2013 at 5:46
  • 9
    Caution! SUBST is practically unusable on a multi-user setup (even if only one real user + an admin). Since a SUBST mapping is user-local, other users won't see it! E.g. you click "Run as administrator" on a shortcut that points to a SUBST-ed place, and it will fail to run.
    – Sz.
    Oct 3, 2015 at 22:51
  • 2
    @PaoloFCantoni, Here: How to make SUBST mapping persistent across reboots? ..
    – Pacerier
    Jan 15, 2016 at 19:20
102

Alternative:

net use x: \\localhost\c$\Folder\Example

The difference between net use & subst below break


subst

When a share becomes unavailable subst will try over and over again to re-connect severely impacting performance of your PC as it tries to re-connect. This is less common when mapping local files as it will only occur if you say re-name the folders in the path. The resolution if this does occur is subst x: /d

net use

net use was introduced in win2k/xp to provide an alternative to this. When net use is used to connect to a location and that location becomes unreachable windows will report drive as disconnected and not try to re-connect until user tries to re-connect to resources on the mapped drive. This resolves the performance issues noted in subst


For more information on both commands you can query via the command line with /?

net use /? & subst /?

15
  • 1
    Normally, since the drive I want to map to is local, I'd use SUBST. However, since it's a USB connected local drive and not always available, will it trigger the problem outlined above? Sep 13, 2013 at 5:19
  • 1
    Good thinking, but as it happens, I'm intending to use it on an ASUS TX300CA Windows 8 transformer tablet which has a detachable keyboard dock On the tablet part there are NO USB ports, so the BIOS must assign the keyboard dock drives (which are USB) before anything else. So they shoudl be stable. I'm sure ASUS would have sorted that. Sep 13, 2013 at 5:45
  • 3
    Besides the retry functionality, is there a difference in performance between the two methods? The net use approach seems preferable but if there is significantly more overhead because it gets the network stack involved I'll use subst since I'm not likely to run into the retrying issue. Jul 24, 2015 at 15:23
  • 8
    For googlers: net use doesn't allow path to contain a trailing backslash, throws a cryptic error 67. Just remove the slash.
    – Steed
    Oct 30, 2017 at 14:06
  • 2
    And when you can't figure out why Explorer etc aren't showing your shiny new drive, recall that Mapped network drives created by an elevated process will not be visible to an unelevated process and vice versa (link also explains how you can tweak the registry to work around that).
    – brichins
    Nov 13, 2017 at 21:43
40

The best way to do this across bootup is to put it in the registry. Open regedit.exe and navigate to

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices

Add a new REG_SZ value and name it X:, where X is your drive letter

The value should be the path in this form

\DosDevices\C:\Folder\Example
5
  • this way allows programs running as administrator to see the drive. subst drives aren't seen. Jul 19, 2018 at 21:59
  • 1
    Do you have to do something (like reboot) to get this to take effect? Nov 10, 2018 at 13:29
  • It should be noted that unless additional steps are taken, files that are deleted from the mapped drive are permanently deleted instead of sent to Recycle Bin (this is apparently true whether you use the registry approach, SUBST, or NET USE). I don't have enough reputation to add a new answer to this question, but I added an answer to a similar question that expands on the registry approach and enables the Recycle Bin. Aug 27, 2019 at 1:16
  • After reboot i still cant access the drive letter
    – Mike Cheel
    Jun 24, 2020 at 19:11
  • This requires a reboot, but otherwise works beautifully. Way better solution than using subst, which is both volatile and user-dependent.
    – Tomalak
    Sep 22, 2021 at 13:57
4

Another way is to put a share on the folder you want to map. You can then use the map network drive option which can be accessed by right clicking on my computer in windows explorer.

Note you will need to turn on network discovery before setting up the share.

The advantage of this approach is you set the option of create on logon.

0

Just to add to the answers above. Another option is a symbolic link which is covered in this SU question How to mount a network drive to a folder?

1
  • Creation of a symbolic link using mlink works beautifully, but it should be noted that you can only use it to create a folder, not a new drive letter. Aug 27, 2019 at 0:54
-6

The best way is through drive management. You can specify a path to mount a drive to rather than a drive letter.

Go to Control Panel -> Admin Tools -> Computer Managment -> Drive Management.

Right click on the volume you want to change, and select Change Drive Letter and Paths.

This way, you can remove the original drive letter all together, and have it mounted under a directory only. This is how you can get around the 24 drive limit in windows.

2
  • 3
    This only lets you create logical driver letter mappings to partitions. It does not allow you to create a logical drive letter mapping to a folder/path/directory, so it doesn't address TC/OP's needs.
    – Cloud
    Nov 18, 2015 at 21:58
  • 1
    What this has to do with question?
    – Kangarooo
    Apr 25, 2018 at 7:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .