How To Automatically Attach VHD Images In Windows 7

Windows 7 users can create virtual hard drive [vhd] images in the Disk Management tool of the operating system. These vhd images can then be mounted and used like any other partition in the operating system. A newly created vhd image gets automatically attached in Windows. At the beginning without a drive letter since it has not been formatted with a file system yet. This can be done in the Disk Management tool as well.

The vhd images will however not be mounted automatically after rebooting the computer for the first time, something that can be of a nuisance to users who have to work regularly with vhd images. Here is a small tutorial on how to automatically mount vhd images in Windows 7 so that they are accessible right after system boot.

1. Create a new text document and add the following two lines to it for every vhd image that should be attached during startup.


select vdisk file=c:\pathtovhdfile
attach vdisk

Save the file and rename it to attachvhd.s

2. Create a new text document and add the following line to it


diskpart -s "c:\pathtovhdattach.s"

Rename the text document to attachvhd.cmd and place it in the Windows startup folder. This ensures that the file will be executed during Windows startup.

This option to automatically attach vhd images uses the diskpart utility which is part of Windows. Diskpart can also be executed separately by entering it into the Windows 7 start menu run box.