Tech and travel

Using the subst command in Windows

2005-08-08

The subst command in Windows XP (and possible earlier versions), allows you to assign drive letters to directories on the local disk. This can be used to create shortcuts in Windows Explorer for directories you use often.

For example let’s assume you have a C: drive, that has a directory called work\project\subproj\code. This is where you store your source code for the current project. Having to go to that directory every time you open Windows Explorer (WE) is a bit of a nuisance, especially because WE doesn’t remember where you were if you close and reopen it.

A way to fix this is to create a new drive, W: for example. This will not be a real drive, but a virtual drive. So the data on it will still be stored on C: . Creating this new drive is done by the subst command, like in this example :

subst w: C:work\project\subproj\code

After having run this in a command prompt, you should see this new drive in WE. This drive will only exist for as long as you are logged in. In other words, if you restart your computer, it will be gone.

If you want this drive to be setup everytime you login, you’ll have to execute the subst command automatically. First add the above subst command to a text file, and give this file a name ending with the .cmd extension.

Then we’ll have this file executed every time we login. This can be done by going to Settings -> Control Panel -> Scheduled Tasks. Right-click and add a new task. Give it a name and then double-click on it to get the properties. In the field called run:, add the newly created .cmd file. In the schedule tab, in the Schedule Task: field, select the At Logon option. Then press OK, and enter your password (if you have passwords for your users, which you really should have for security reasons).

That’s it. This command file will be executed every time you login, giving you a convenient shortcut to your work files.

Copyright (c) 2024 Michel Hollands