Does Windows (XP or later) have a built-in way to create persitent drive mappings, like the ones SUBST creates? I found a 3rd party tool psubst. Is there a way to do it without 3rd party tools?
11 Answers
Well Wikipedia mentions:
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.
So you can associate paths with drive letters using subst. The Persistent SUBST command (psubst) software seems to be darn handy, and they provide a solution to run it from startup:
https://github.com/ildar-shaimordanov/psubst#Inconstancy
Inconstancy
However restart of a system destroys a virtual disk. What to do? A disk can be created after startup. But what to do, when a disk is needed on early steps of a startup? For example, to run services? There is system feature to start a virtual disk from the system registry:
REGEDIT4[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices] "Z:"="\??\C:\Documents and Settings\All Users\Shared Documents"
It is enough to create a text file with the extension
.REGand run it. When the next starting up of a system, the virtual disk will be exist at logon. It needs to define a name of disk and path. Note that each backslash in the path is doubled.
In Windows, you can run the registry editor as follows:
- Start » Run... (or hit Win+R)
- Type:
regedit - In Windows Vista and above, UAC will pop up, click "Yes".
- 859
- 24,894
Installing it at HKEY_CURRENT_USER has the benefit of having different setups for each user. I prefer to stick the user space setup as long as a system service does not depend on the device.
REGEDIT4
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]
"F Drive"="subst F: D:\\mount\\db"
"G Drive"="subst G: D:\\mount\\log"
Source: http://networkadminkb.com/KB/a446/how-to-use-drive-letters-mount-points-the-same-disk-drive.aspx
- 1,471
There's an answer in the page you linked to. You don't need the third party tool, you can do it with a simple registry entry, as detailed on that page.
Create a text file named 'mapdrive.reg' with these contents:
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices]
"Z:"="\\??\\C:\\Documents and Settings\\All Users\\Shared Documents"
Then should just be able to double-click on it to set up, no 3rd party tools needed.
I found this because I was looking for an improvement over my startup subst scripts - they worked OK, but sometimes executed after folders crashed on startup because my drive wasn't yet mapped.
First, I edited the registry, but was unable to get it to work. However, I did come across this alternative, which although it doesn't use subst does answer for me the question, "How to make SUBST mapping persistent across reboots?" Don't use subst... (insert appropriate 'computerName' and 'pathName'):
net use u: "\\computerName\c$\pathName" /persistent:yes
I adapted this from Hank Arnold's suggestion at this discussion of mapping local drives. I had guessed that \\myComputerName\c might work, but I didn't know to apply the $.
Before you try the "net use" command, try to navigate to
\\computerName\c$to make sure you have 'computerName' correct.
- 1,227
Drop a batch file in your Startup folder that does all the SUBSTs that you want to do.
- 9,655
I am expanding on davr's answer because any files that are deleted from the mapped drive are permanently deleted instead of going to the Recycle Bin. This REG file is based on the information compiled from this TechNet article, which discusses how to enable the Recycle Bin. The example maps the virutal Q drive to folder "OneDrive - Test", and enables the Recycle Bin on the Q drive. Change the paths and name to suit your situation.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices]
"Q:"="\\??\\C:\\Users\\Tony\\OneDrive - Test"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{9147E464-33A6-48E2-A3C9-361EFD417DEF}]
"RelativePath"="Q:\\"
"Category"=dword:00000004
"Name"="Q_Mapped_OneDrive"
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\KnownFolder\{9147E464-33A6-48E2-A3C9-361EFD417DEF}]
"MaxCapacity"=dword:0000c7eb
"NukeOnDelete"=dword:00000000
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{9147E464-33A6-48E2-A3C9-361EFD417DEF}]
"RelativePath"="Q:\\"
"Category"=dword:00000004
"Name"="Q_Mapped_OneDrive"
[HKEY_CURRENT_USER\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\KnownFolder\{9147E464-33A6-48E2-A3C9-361EFD417DEF}]
"MaxCapacity"=dword:0000c7eb
"NukeOnDelete"=dword:00000000
If you only have one such mapped drive, then you can get away with the GUID {9147E464-33A6-48E2-A3C9-361EFD417DEF}. If you have multiple mapped drives, then each should be matched to a GUID from your favorite GUID generator.
- 271
Since the original PSubst has some limitations and seems to be concluded by the author, I had to code a new version for my needs, fixing some problems and adding functionality and flexibility.
Check here for PSubst version 3 batch file
https://github.com/cyberponk/psubst
Compatible with Windows 7, Windows 8, Windows 10, Windows Server 2012
Note: This work has no intention of demeriting the original author and only came to existence because of real necessity, as follows:
As a newtork admin I have the constant need for SUBST´ing network drives and fiddling with different network users.
As not everyone is a Windows expert, i figured the automatic admin elevation with error handling would help, based on coments I read through the web.
As some people struggled with the arguments order, I figured it would be best for the script to work with arguments in any order.
I can´t recall of every added functionality, but every inclusion was done purely by necessity. I am sharing the code so that others may not encounter the troubles I had. By this there is no intention other than sharing and helping.
- 221
Here are two examples using reg.exe to add the required entry to the Run Registry subkey of the HKEY_CURRENT_USER hive. These examples can be adapted as required. Open an unelevated cmd window as the current user, and paste in the adapted line.
The simplest use-case:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "Map I" /t REG_SZ /d "subst I: \"C:\path\to\folder\"" /f
Where SUBST's path argument has an environment variable embedded in it:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "Map J" /t REG_EXPAND_SZ /d "subst J: \"^%DROPBOX_HOME^%\Notes\"" /f
Note that there are two lots of character escaping in the second example. Backslashes for the inner double-quotes that surround the path argument, and carets for the environment variable's percentage signs. Double-quotes aren't always required, but to avoid problems with folder names containing spaces it's recommended to use them.
- 1,522
- 1
- 11
- 15
I know the question was asked more than 10 years ago and I can see the last answer was given about half of year ago... Nevertheless I feel necessity to update this thread with my answer, because the psubst tool is mentioned here (as the version by @cyberponk). It has been updated to the version 3.0.1 and enhanced to persist drives with elevated privileges in simple way.
https://github.com/ildar-shaimordanov/psubst
The above link follows to the repository of the original tool.
- 131
SUBST is useful to give a short path to access a set of files. However, if you don't need access at the original location then a virtual drive may be a useful alternative.
I'm used to having a separate D:\ drive for my projects, but partitions cause problems when one runs out of space while there is still plenty on the other. A .vhdx virtual drive can be set up to only consume space when data is written to it.
- Open the "Disk Management" control panel item
- Select the drive where you wish to place the image
- Select "Create VHD" from the actions menu
- Enter the location, size and options for the drive
- Right-click the newly mounted "Disk" (the grey bit to the left) and initialise the drive
- Right-click the unallocated space and add a new volume
- Choose the size, format and drive letter
Like SUBST this gives you a drive identified by a letter i.e. D:. However, unlike SUBST this is a drive in it's own right and has the full set of windows features, e.g. deleted files go to the recycle bin. It is also mounted automatically on each boot. The drawback is you can't access the files from the original location.
- 185
I settled on this solution. Its more complete than a similar one. Drop a batch file in your Startup folder that does all the SUBSTs that you want to do.
- Create a batch file with the
substcommands - Type Windows + R to 'run'
- And type in
shell:startup - Create a shortcut in the Startup Folder for the batch file.
Its best to not copy files into the Startup folder, so that the files don't get deleted accidentally if you clear the Startup folder.
- 5,096