83

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.

89

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

  • 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? – PaoloFCantoni Sep 13 '13 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 '13 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. – PaoloFCantoni Sep 13 '13 at 5:46
  • 6
    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 '15 at 22:51
  • 2
    @PaoloFCantoni, Here: How to make SUBST mapping persistent across reboots? .. – Pacerier Jan 15 '16 at 19:20
87

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 /?

  • 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? – PaoloFCantoni Sep 13 '13 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. – PaoloFCantoni Sep 13 '13 at 5:45
  • 2
    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. – Jay Paroline Jul 24 '15 at 15:23
  • 5
    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 '17 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 '17 at 21:43
29

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    
  • this way allows programs running as administrator to see the drive. subst drives aren't seen. – Jean-François Fabre Jul 19 '18 at 21:59
  • Do you have to do something (like reboot) to get this to take effect? – DaveInCaz Nov 10 '18 at 13:29
2

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.

1

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?

-5

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.

  • 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. – DevNull Nov 18 '15 at 21:58
  • 1
    What this has to do with question? – Kangarooo Apr 25 '18 at 7:34

protected by Community Feb 22 '17 at 10:31

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.