ghacks Technology News

Automatically Attach VHD Images [Windows 7]

The Windows 7 operating system comes with the option to create virtual hard drive [vhd] images that can be mounted in the operating system after creation. This works pretty much the same way that iso images and other disk images can be mounted in an operating system. VHD images are automatically attached after their creation but never again automatically after the computer system has been rebooted. This is a nuisance for users who need to work regularly with the same vhd image on the computer system.

An easy option to automatically attach vhd images is to use the diskpart command line utility which is part of the Windows 7 operating system. Diskpart is a powerful tool to enable storage configuration from the command line (as well as remote sessions and scripts).

Diskpart can be lauched manually by typing in diskpart in the run box in the Windows 7 start menu. This will open a new command line window with Diskpart launched.

The first command specifies the vhd image that should be attached to Windows 7:

select vdisk file=c:\pathtovhdfile

The second command attaches the specified vhd image

attach vdisk

This is the manual process. To automate the process of attaching a vhd to the system do the following. Create a new text document and place the two lines mentioned above in it. You can add those two lines again for every vhd image that should be automatically mounted during system start. Save the file as vhdattach.s

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

diskpart -s “c:\pathtovhdattach.s”

Rename the text document to diskpart.cmd and place this file in the startup folder in the Windows start menu. Diskpart.cmd will be executed on startup of the operating system. It will process the commands in vhdattach in diskpart so that the vhd images will be attached to the system.

It might be necessary on the first run to go into the disk management tool to format the vhd drives in Windows so that drive letters are assigned to them. The Disk Management tool can also be used to detach vhd images.

Enjoyed the article?: Then sign-up for our free newsletter or RSS feed to kick off your day with the latest technology news and tips, or share the article with your friends and contacts on Facebook or Twitter.

Related Articles:

4chan Downloader Saves All Thread Images Automatically
Opera Make It So Extension Resizes Images Automatically
Gmail Starts Displaying Images Automatically For Contacts
ImageSorter sorts images automatically
ImageFit, Scale Images Automatically In Firefox



About the Author:Martin Brinkmann is a journalist from Germany who founded Ghacks Technology News Back in 2005. He is passionate about all things tech and knows the Internet and computers like the back of his hand. You can follow Martin on Facebook or Twitter.

Author: , Thursday January 14, 2010 -
Tags:, , , , , ,


Responses so far:

  1. Kendall says:

    I made a program that will attach VHD automatically on startup.

  2. Chad Krause says:

    Whenever I do it, an error occurs.

    DiskPart has encountered an error: The file or directory is corrupted and unable. See the System Event Log for more information. There is no virtual disk selected.

  3. Mark says:

    Thank you! Though you need quotes around the select vdisk statement:
    select vdisk file=”C:\Virtual Drives\dirvex.vhd”

  4. AbuAljazer says:

    Diskpart.cmd is a bad name, using Diskpart.cmd will make it run in an infinite loop!!!

    Use AttachVHD.cmd instead.

  5. Chan says:

    Thanks so much, It is really useful to me

  6. r4k4 says:

    Thank you very much, your post already being a part of my break through.. :)

    I created my own “DiskPartConf.s” like this:

    select vdisk file=D:\VHD_Collection\delicious.vhd
    attach vdisk

    I created my own “DiskPartConf.cmd” like this:

    @echo off
    diskpart.exe -s “D:5_Kreasi\DiskPartConf.s”
    echo.
    pause

    I put shortcut into my own “StartUp Folder” and set it to be “Run as administrator”

    Any comments for better improvement are welcome.. :)

Leave a Reply   Follow Ghacks   Subscribe To Comment Rss

Subscribe without commenting

© 2005-2012 Ghacks.net. All Rights Reserved. Privacy Policy - About Us