MynaG's Bits n Bytes

09 Jan, 2013

Use a virtual drive letter as folder in Windows using subst

Posted by: mynag In: Solutions & Tips|Windows

There are many reasons that you will want to substitute a folder as a drive. One of them is for convenience especially if you need to work in a command prompt environment and typing a drive letter is much easier than typing a long path name. A few years ago, I have also used this method to associate a folder with the drive letter A: in newer computers without a floppy drive because at that time some legacy programs persisted in reading or writing to floppy drives and without a drive letter A:, it simply will not work.

So here is what you can do.

  1. Create a folder where you want it to be read as your virtual drive. Example: c:\virtual_drive.
  2. Click the Start button and at the “Search program and files” text box type command.com.
  3. At the command prompt, type the following

    subst f: c:\virtual_drive

    f: being the drive letter you want to assign as a virtual drive and c:\virutal_drive being the path of the folder where you want it to be seen as the virtual drive.
    Note that the drive letter you are assigning must not already been used otherwise it will not work.

You can now access the contents in the virtual drive folder just as a drive letter in the Windows environment.

To remove the virtual drive link, simply type the following at the command prompt and press ENTER.

subst f: /d

f: being the drive letter you have assigned as a virtual drive.

If you want to know what are the virtual drives that you have assigned, simply type and run SUBST in the command prompt and you will be presented with a list of the currently assigned virtual drives.

However, the virtual drive assignment using SUBST is not permanent and will be lost after your computer is rebooted. So to keep the virtual drives upon restarting, there are a few methods.

Startup Folder

This is probably the simplest method. Open Notepad and create a batch file (e.g. set_virtualdrive.bat) and write the command as in Step 3 (e.g subst f: c:\virtual_drive) in the batch file and placed the file in the Startup folder.
To locate the Startup folders, click the <Start> button and click <All Programs>. Scroll down the list until you see the folder <Startup>. Right mouse click on the <Startup> and click <Open> if the virtual drive assignment is only specifically for your user account. Click <Open all users> if you need the drive assignment to affect all users of the computer.

For a specific user account, the location of the Startup folder is
C:\Users\<USER LOGIN NAME>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

For all users, the location of the Startup folder is
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

At anytime, you can modified the batch file to add or remove any virtual drives assignment.
To stop the virtual drive assignment permanently, simply delete the batch file at the Startup folder.

Registry

Another method is to use the registry method. It is always recommended to backup the registries before you attempt to make any changes to it. You can create a registry file to run the virtual drive assignment every time Windows start up. Open notepad and type in the following.

REGEDIT4
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
“Virtual Drive F”=”subst f: d:\\virtual_drive”

f: being the drive letter you want to assign as a virtual drive and c:\virutal_drive being the path of the folder where you want it to be seen as the virtual drive.

Save the file as a registry file (*.reg) such as Temp.reg at any preferred location. Double clicked on the registry file you have just created or right-click on it and click <Merge>.

A pop up dialog will appear to warn you about continuing if the registry is not from a trusted source. Click <Yes> to proceed.

For assignment of virtual drives to all users, use the following scripts in the registry file instead.

REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
“Virtual Drive F”=”subst f: d:\\virtual_drive”

Another way is to use the Regedit (Registry Editor).

  1. Run the program by typing Regedit in the “Search Program and files” text box at the START button. You may have to be an administrator rights to run Regedit.
  2. Expand the the folder tree on the right and locate the correct folder.For virtual drive assignment specifically for your user account. Go to the folder at HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
    For virtual drive assignment for all users. Go to the folder at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
  3. Right click on the right pane. Click New > String value.
  4. Overwrite the default name with a more descriptive name such as Virtual Drive F.
  5. Double-click on the name and enter “subst f: d:\virtual_drive” as value.The line should look like this:  Virtual Drive F      REG_SZ              subst f: d:\virtual_drive
  6. Repeat step 3 to add more virtual drive assignments.

To remove virtual drive assignment permanently, simply select the string value that contains the virtual drive assignment and delete it from the registry.

2 Responses to "Use a virtual drive letter as folder in Windows using subst"

1 | Nohype

July 10th, 2014 at 1:07 pm

Avatar

[correction]

“For assignment of virtual drives to all users, use the following scripts in the registry file instead.”

must be:

REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
“Virtual Drive F”=”subst f: d:\\virtual_drive”

2 | mynag

August 26th, 2014 at 6:17 pm

Avatar

I have made the correction. Thanks Nohype!

Comment Form

Categories

About

Welcome to MynaG's Bits and Bytes. My little journal containing bits and bytes of the internet, web programming and etcetera