Sunteți pe pagina 1din 6

psubst - Project Hosting on Google Code Page 1 of 6

My favorites | Sign in

Support browsers that contribute to open source, try Firefox or Google Chrome.

psubst Search projects

Persistent SUBST command

Project Home Downloads Issues Source

Summary | Updates | People

Persistent SUBST command Activity: Medium

Code license:
Abstract GNU General Public License v2

Associates a path with a drive letter and extends the standard SUBST command allowing to create Labels:
persistent substituted drives between startups. windows, command-line-interface,
commandlineinterface, windows-
registry, windowsregistry, registry,
History virtual-drive, virtualdrive, persistent-
subst, persistentsubst, persistent,
permanent, SUBST, REG, REGEDIT

Featured downloads:
Show all »

Project feeds


People details »

2009/03/06 - Version 2.4 Stable. Earlier, to see persistent drives the 'REG QUERY' command was made to the temporary file. Now
2009/01/27 - Version 2.3 Stable. Separate view for the SUBSTed disks and persistent SUBSTed disks. Thus PSUBST /P shows persistent disk
2008/09/22 - Version 2.2 Stable. The minor bug was fixed: Unable to remove record from the registry when drive was unsubstituted alread
2008/09/04 - Version 2.1 Stable. Tests has been provided and it works properly. 6/23/2010
psubst - Project Hosting on Google Code Page 2 of 6

2008/09/02 - Version 2.0 Beta. Now the REG utility is used instead of the REGEDIT.
2008/09/02 - Version 1.2. The problem of quoted arguments in the IF "%*" == "" construction was fixed.
2008/08/31 - Version 1.1. Minor changes (the more accurate init of vars, unified names of vars).
2008/08/30 - The first release.

Divide and power

Since oldest times in Windows there is admirable feature to map some path with name of a virtual drive using the SUBST command. This feature
makes the simpler an access to objects on a disk. It means a usage of name of a virtual drive instead of a long path. For example, the following
command is used to create virtual drive Z for the path C:\Documents and Settings\All Users\Shared Documents:

subst Z: "C:\Documents and Settings\All Users\Shared Documents"

So to reach targets in this folder it does not need to type the full path or go over a tree of folders in the Explorer window. To select the Z: drive is

Do we need it?
There is several certain examples when this feature is needful:

Temporary stub when the physical drive is missing;

Operational system limitation for the size of filename (256 characters);
Working of some application within own space;
Emulation of other operational systems.

How does this work?

Create new virtual drive:

subst Z: "C:\Documents and Settings\All Users\Shared Documents"

Delete virtual drive:

subst Z: /D

Print a list of existing drives: 6/23/2010
psubst - Project Hosting on Google Code Page 3 of 6



Indefinite format

There is strong agreement about a correct typing of the substituted path:

1. a path should not be trailed by a backslash;

2. the root path should be ended by a backslash.

For example, these are correct

subst Z: "C:\Documents and Settings\All Users\Shared Documents"

subst Z: C:\

But these are incorrect:

subst Z: "C:\Documents and Settings\All Users\Shared Documents\"

subst Z: C:


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:


[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 .REG and 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. 6/23/2010
psubst - Project Hosting on Google Code Page 4 of 6

Can it be joined?

Answer is yes! This article is the result of the work devoted to availability of joining both features. The batch script was developed for cover
problems described earlier. Also it adds a lot of owned features.

Overview of the new features


As well as the standard SUBST command this script named as PSUBST.BAT implements all standard features of the command.

Create a disk:

psubst drive1: drive2:path

Delete a disk:

psubst drive1: /D

Print of existing disks:



Typing the /P argument you run the script with the extended features to work with persistent virtual disks.

Create a persistent virtual drive with saving in the registry:

psubst drive1: drive2:path /P

Create a virtual drive reading about it from the registry: 6/23/2010
psubst - Project Hosting on Google Code Page 5 of 6

psubst drive1: /P

Delete a drive and wipe out a record from the registry:

psubst drive1: /D /P

Print all virtual persistent drives (read from the registry)

psubst /P

Additional features

Great advantage of the script is independency of existence or lack of the trailing backslashes. It means that incorrect examples described earlier
in this article will work always – incorrect input arguments will be transformed to the required format and the command will execute substitution
successfully. Nevertheless the standard command works with the slashes in a path correctly, the script transforms these to backslashes usual in

New shortcomings

Are there owned shortcomings? Exactly! There are:

this is batch script and it works slower than binary analog;

there is probability to run script twice with different arguments and disturb results of both;
there is probability to break a script execution when disk have been created but the registry is not updated.

But there are so little things.

How to install?
Download the archive following by the download link, unpack it or checkout the source and locate the single file to comfortable place in your hard

Related links
SUBST home 6/23/2010
psubst - Project Hosting on Google Code Page 6 of 6

Persistent subst for NT-clones (by Alexander Telyatnikov)

C++ coded PSUBST (by Alexander Telyatnikov)
Overview of file systems FAT, HPFS and NTFS (Microsoft knowledge base page in Russian)
How NTFS Works
The same text in Russian

©2010 Google - Terms - Privacy - Project Hosting Help

Powered by Google Project Hosting 6/23/2010