iTranslated by AI
Creating a Temporary Virtual Drive for Work on Windows
Introduction
In this article, I will explain how to create a virtual temporary drive using the Windows subst command.
I will also explain how to automatically create a temporary drive using Windows Task Scheduler.
With a temporary drive, you can safely perform tests or save temporary files at any time.
This will be a step towards improving your productivity.
1. What is subst?
subst[1] is a Windows command that treats a specified directory as a virtual drive.
1.2 Usage of subst
subst is used with the following syntax:
subst [virtual drive]: [full path]
For example, entering the following maps the c:\tmp directory as the Z drive.
subst z: c:\tmp
This allows you to access the contents of c:\tmp through the Z drive.
For detailed options and use cases, please refer to the official subst documentation.
2. Temporary Drive Creation Script
This section explains the script used to create a temporary drive.
2.1 Script Description
This script creates a temporary drive every time Windows starts.
Therefore, save it with the specific name "c:\bin\init\zdrive.cmd".
@echo off
rem
rem create Z drive for temporary
rem
rem @Author atsushifx
rem
path c:\windows\system32;%path%
setlocal
set _tmpdrv=C:
set _tmpdir=%tmpdrv%\tmp
rem Create working directory
if not exist %_tmpdir%\NUL goto endtmpdir
rmdir /s /q %_tmpdir%
:endtmpdir
mkdir %_tmpdir%
rem Create temporary drive
if exist Z:\NUL goto endtmpdrive
C:\WINDOWS\system32\subst.exe z: %_tmpdir%
:endtmpdrive
rem Create subdirectories for work
mkdir z:\temp
mkdir z:\works
3. Automatically Creating a Temporary Drive Using Task Scheduler
By adding a task to Task Scheduler[2], you can have Windows automatically call the script created in section 2.
This ensures that the temporary "Z drive" is available automatically every time you use Windows.
3.1. Creating a Task to Create a Temporary Drive
To automatically create a temporary drive, create a task using the following steps.
This task is called during Windows startup and logon to automatically create the temporary drive.
-
Launch Task Scheduler:
Launch [Task Scheduler] from the Start menu to open [Task Scheduler].

-
Create a New Task:
Select [Action] - [Create Task] to open the [Create Task] dialog.

-
Set the Task Name:
Select the [General] tab and enterzdrivein [Name]. Also, check "Run whether user is logged on or not".

-
Set the Triggers:
Select the [Triggers] tab and click the [New] button to create a trigger. Select [At startup] and [At log on] for the triggers.

-
Set the Actions:
Move to the [Actions] tab and click the [New] button. Register "c:\bin\init\zdrive.cmd" as the script.

-
Exit Task Scheduler:
Click [OK] to close each dialog. Then, close Task Scheduler by selecting [File] - [Exit].
This completes the task setup.
A temporary drive will now be created automatically every time Windows starts.
3.2. Exporting the Task for Creating a Temporary Drive
Export the created task. By doing this, you will be able to use the temporary drive immediately when rebuilding your Windows environment.
Export the task using the following steps.
-
Select the Task:
In the [Task Scheduler Library] screen of Task Scheduler, select the created "zdrive".

-
Export the Task:
Select [Action] - [Export] to export the task. -
Save the Export File:
Save the exported task to a file.
This completes the task export.
With the exported file "zdrive.xml", the temporary drive will be available when rebuilding your Windows environment.
3.3. Importing the Task for Creating a Temporary Drive
You can import the task using the "zdrive.xml" file exported in section 3.2.
This allows you to use the temporary drive even immediately after a fresh Windows installation.
Import the task using the following steps.
-
Task List:
Open the [Task Scheduler Library] screen of Task Scheduler.

-
Import the Task:
Select [Action] - [Import Task] and select the created "zdrive.xml" file. -
Task Settings:
The [Create Task] dialog will be displayed, so click [OK].

This completes the task import.
Conclusion
In this article, I introduced how to create a temporary drive using the Windows subst command. I also introduced how to automatically create a temporary drive using Task Scheduler.
Now you can try out small scripts and programs on a temporary drive.
This should make your programming and development work more efficient.
Happy Hacking!
Discussion