Mapping drive letters to local folders

91

38

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.

PaoloFCantoni

Posted 2013-09-13T03:51:26.497

Reputation: 1 583

Possible duplicate of How do I mount a network drive to a folder?

– Cristian Ciupitu – 2018-09-19T09:17:16.463

Answers

92

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

Josh

Posted 2013-09-13T03:51:26.497

Reputation: 4 746

6Caution! 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. – 2015-10-03T22:51:16.563

2

@PaoloFCantoni, Here: How to make SUBST mapping persistent across reboots? ..

– Pacerier – 2016-01-15T19:20:59.483

2Yes, 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 – 2013-09-13T04:47:30.287

1Have 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 – 2013-09-13T04:54:49.150

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 – 2013-09-13T05:46:41.687

92

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

50-3

Posted 2013-09-13T03:51:26.497

Reputation: 3 779

NET USE simply cannot be used on my work. I'm not an admin, nor I'm allowed to share any folder. SUBST is a better option in that case. – rsenna – 2014-11-07T20:22:47.690

You can assign a USB drive a drive letter. This is the simple command line procedure.

– DDay – 2015-06-09T13:53:53.877

3Besides 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 – 2015-07-24T15:23:06.973

@50-3, Nice answer. Btw how did you get the information for this post? Is there a citation/source? – Pacerier – 2016-01-15T19:22:45.930

@Pacerier http://ss64.com/nt/ is my main source for windows CLI

– 50-3 – 2016-09-19T01:50:04.313

AFAIK SUBST only applies to the current logged in user. This means not everything will work as expected. For example, if you try to install an MSI from a SUBST drive, it will fail because the Windows Installer service will attempt to access the drive and fail. – Joe – 2016-10-10T08:25:37.463

7For googlers: net use doesn't allow path to contain a trailing backslash, throws a cryptic error 67. Just remove the slash. – Steed – 2017-10-30T14:06:53.797

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 – 2017-11-13T21:43:11.887

The problem with net use is that it requires the folder to be shared whereas subst works on any folder without having to expose it to the network. – Synetech – 2018-02-15T17:57:59.013

this post quoted here: https://www.itworld.com/article/2694895/how-to-map-a-local-folder-to-a-drive-letter-in-windows.html

– ashleedawg – 2018-07-21T19:43:21.107

writing the path as \\localhost\c$\ allow me to access local folders via the "map network drive" GUI. Thanks for that piece of inspiration. \\localhost\c\ and C: didn't work. – craq – 2019-02-15T00:22:09.223

1Normally, 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 – 2013-09-13T05:19:25.997

Why yes it would - however I'm not sure how you would correctly address it as a USB might not be assigned the same drive letter every time it's plugged in – 50-3 – 2013-09-13T05:21:37.977

1Good 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 – 2013-09-13T05:45:06.133

At least you should now have a good grasp on your options. Do us a favor and upvote @Josh his answer was high quality and answered your original questionp perfectly – 50-3 – 2013-09-13T05:58:10.443

31

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    

Jeff H

Posted 2013-09-13T03:51:26.497

Reputation: 411

this way allows programs running as administrator to see the drive. subst drives aren't seen. – Jean-François Fabre – 2018-07-19T21:59:58.683

Do you have to do something (like reboot) to get this to take effect? – UuDdLrLrSs – 2018-11-10T13:29:37.367

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.

– Tony Pulokas – 2019-08-27T01:16:23.743

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.

Mike payne

Posted 2013-09-13T03:51:26.497

Reputation: 21

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?

user986363

Posted 2013-09-13T03:51:26.497

Reputation: 123

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. – Tony Pulokas – 2019-08-27T00:54:40.973

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

Kevin

Posted 2013-09-13T03:51:26.497

Reputation: 31

3This 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 – 2015-11-18T21:58:41.630

1What this has to do with question? – Kangarooo – 2018-04-25T07:34:11.980