Virtual Hard Disk (VHD) is a file, created in Windows 7, that behaves as a separate usual hard disk drive of the computer. You can keep your favorite files and folders, apply disk encryption etc. Even, you can boot from that virtual disk drive by configuring the boot manager. This tutorial shows how to create a virtual disk drive in Windows 7, attach an existing VHD and lastly, the procedure of making the attachment permanent in step by step.
Create Virtual Hard Disk (VHD)
You can create a virtual hard disk from Computer Management wizard.
Right-click on My Computer and select “Manage”.

or, type compmgmt.msc at the Windows 7 start menu search box and hit Enter. The Computer Management wizard will appear. Now follow the steps below.
Right-click on “Disk Management” under “Storage” and click on “Create VHD”.

In the next wizard select the location and the VHD file name by clicking on “Browse”, put the size of the virtual hard disk in MB and click on OK.

This will create the Virtual Hard Disk with the level Disk 1.

Now right-click on Disk 1 and select initialize then click “Next”.

After initializing the disk, you have to allocate the disk space. So right-click on the unallocated space and select “New Simple Volume”.

In “New Simple Volume” wizard put the volume size and click on “Next”.

Assign a drive letter for the drive by choosing from the drop down list of available letters. Click on “Next”.

Before formatting the volume, choose the file system, give a volume level and click on “Next” then “Finish”.

You are done! You can notice that your new virtual hard disk has been listed with the other disk drives.

Attach an existing Virtual Hard Disk
Right click on My Computer icon then select “Manage” to open Computer Management wizard. Now under the “Storage” entry, right-click on “Disk management”. Select “Attach VHD” and locate the existing vhd file and click on OK. That’s all.
So after creating a new Virtual Hard drive or attaching an existing one, you can access it from the Windows 7 explorer window.

But the problem is that every time you restart your computer, you lost the virtual drive and you’ll have to reattach the VHD again. There is a simple tricks by which you can make the virtual drive permanent and you won’t have to reattach that after every time you start your computer.
Related: Create Virtual Drive for any folder.
Permanently attach Virtual Hard Disk in Windows 7
To make the virtual hard disk permanent, create a batch file to attach the VHD and run that at start up by creating a registry entry. Here is the complete procedure.
Creating the batch file
Copy the following code and paste in a notepad document.
@echo off
SET TEMPFILE="%TEMP%\%RANDOM%.TXT"
echo SELECT VDISK FILE=Your vhd file name with location >%TEMPFILE%
echo ATTACH VDISK>>%TEMPFILE%
DISKPART /s %TEMPFILE%
del %TEMPFILE%Replace the high lighted part with the vhd file name along with location. As for example E:\myvirtualdrive.vhd
Now save the file as some_name.bat. Also change the “Save as type” to “All files” before saving. After creating the batch file copy the file (some_name.bat) and paste at C: > Windows > System 32 folder. When pasting the file there you will get a security message. Just click on “Continue”.
Creating the registry entry
Press Win key + R and type “regedit” and hit Enter to open the registry editor. Now navigate to the following path from the left pane of the editor:
HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > Windows > CurrentVersion > RunNow create a new string value under “Run”. Right-click on the empty space of the right pane and select New > String Value.

Give a name of the value. Here it is VHD. Now right click on the value VHD and select “Modify”.

At the Value data field put “c:\windows\system32\some_name.bat” and click OK.

Restart your computer. You can notice the virtual drive that you created or attached has been permanently occupied in the explorer or any other places.
I tried this just now – It doesn’t seem to be working for me. I’ll try it again, but when I restarted my computer the drive didn’t even exist.
Tried it a second time. Still no luck, when the computer restarts, there’s no virtual drive listed in my computer. :/
The only thing that comes up as different is that when I click atach to the virtual disk, it tells me that it’salready attatched. – could this have something to do with my problem?
Anj: The procedure works fine. I tested that several times. Confirm that you are creating the registry key at the exact location where i said. One more thing when you copy the batch script then please retype the ” signs from your keypad.The problem may be with the rich font.
I created a VHD on a network drive and was able to do a backup to it. So it worked! However, when I try to reattach to the drive later after rebooting, I get the error message: “This version does not support this version of the file format”. Any ideas?
Are you trying with NTFS format?
Yes, I used NTFS.
diskpart -s doesn’t seem to work for me. The command prompt just flashed and closed. But it worked if I did line by line inside diskpart command prompt.
What am I missing?
Put the following code:
@echo off
SET TEMPFILE=”%TEMP%\%RANDOM%.TXT”
echo SELECT VDISK FILE= put your VHD file name with its location >%TEMPFILE%
echo ATTACH VDISK>>%TEMPFILE%
DISKPART /s %TEMPFILE%
del %TEMPFILE%
Remember that if copy this code then paste, you should re-type the ” (quotes) from your keyboard.
Let me know if this solved your problem.
you have to put the path in “”
e.g.
@echo off
SET TEMPFILE=”%TEMP%\%RANDOM%.TXT”
echo SELECT VDISK FILE= “C:\virtuadriveyouspecify.vhd” >%TEMPFILE%
echo ATTACH VDISK>>%TEMPFILE%
DISKPART /s %TEMPFILE%
del %TEMPFILE%
what a waste of time, it doesnt work, u have to reattach it every time :-|
It probably needs to have the correct permissions to work, which are not accounted for in this process.
A much more elegant solution that doesn’t require manipulating the registry is here: http://coding.infoconex.com/post/2009/11/26/Automatically-attaching-VHD-files-in-Windows-7-and-Windows-2008.aspx
Just be sure to read all the comments as well and adjust the Administrator settings accordingly.
what would be code to display two virtual drives???
Yea I did all that, changed the ” and still nothing everytime I restart. Getting annoying. Followed it step by step.
Working with windows 7. I restart it and comes up with CMD saying do I want to make those changes, click yes and nothing.?????
Has anyone confirmed that their batch file actually works before using it in a reboot scenario? Detach the VHD and run the batch. If that works, then figure out 1. Why the batch is not executing at boot time and/or 2. Why it does not attach the vdisk..
Also, all versions of Windows may not be supported. I know that you cannot _boot_ to a Windows 7 Home edition vdisk. Perhaps there are restrictions on mounting at boot time as well…
Is there a way to undo this?
I created the script and tested it on Win7-Pro and it works. The VHD is attached and usable. I then made the regedit change and rebooted. It brought up Notepad with the script in it. I tired changing the default assignment of .bat files from Notepad to CMD.exe and made things worse. Now it brings up a Command window which just sits there. I can drag a copy of my .bat file into the window and execute it, but that is way clumsy. I tired reversing the default assignment of .bat files back to Notepad, but that doesn’t take. It is now permanently glued to CMD.exe. A
Any idea how to undo that assignment and what the assignment should be?
ahhaha thanks..
works for me..
no need to reattached after restarting..
yea!!!
Dear All,
Its attach, but each and every restart its reloading, again i need give permission
Is there any solution for this problem
Thanks in advance, i hope i may get good response from your end
This worked perfectly! Is there a way to make the VHD available while booting the OS to make the choice of other OS installed in the VHD?
am I lost something? I don’t understand the 3rd picture. where is the ” vhd_sample.vhd ” come from? does it download from website? please help me….