UGTS Document #41 - Last Modified: 8/29/2015 3:23 PM
Path Standardization with the SUBST Command
When synchronizing files between several machines, and those files contain shortcuts and links, you often would like a way to point to the local copy of the file in a way which is standard across many machines, though the file may not be stored in the same absolute directory on every machine.
The simplest solution is to use relative paths, but this is only an option where you can guarantee that the relative structure between the source and the destination won't change. If you move the source or destination, you must guarantee that they will move together as a unit and the relative path between the two will not change.
If this is not the case, you still have a few options. Shortcut (LNK files) can use environment variables in the path and still work. For example, if you define a machine environment variable called LOCALSHARE, and point it to C:\fileshare, then you can use %LOCALSHARE%\run\App\MyApp.exe to point to C:\fileshare\run\App\MyApp.exe. This has the advantage that it is defined at the machine level and will work even before a user logs in. However, if is only usable in a limited number of places - shortcut files, batch files, and at the command prompt. It will not work for hyperlinks in Word or Excel files or a number of other places.
Another solution which sometimes works is to use UNC paths, and to share a folder on each machine in the appropriate place. You can then define machine alias name, so long as the security feature 'strict name checking' has been turned off in the registry. You can also use \\localhost to refer to the current machine. However, this has the problem that even if the UNC path refers to the machine you are on, the path won't work if the machine is disconnected from the network (which can happen if the machine is a laptop with wireless disconnected). Therefore, UNC paths are only useful in places where you only need to use them while connected to the network, such as for synchronization between machines.
Another solution which is fairly robust is to use virtual drives. The DOS 'SUBST' command can map a drive letter to a folder, which is usable by nearly all programs. However, drive letters assigned in this way do not persist across system restarts. To define a persistent mapping, create a registry value:
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices value = X:
In the example, replace X: with the drive letter to be mapped, and set the value to:
Where Y:\My\Path is to be replaced with the absolute path that the drive letter is to point to. Note that after doing this, the drive letter won't be available until you restart the computer (just logging out and logging back in is not enough).
Paths using SUBST drive letters have a fair share of limitations that you need to be aware of: