How-To Geek
Mount and Unmount a VHD File in Windows Explorer via a Right-Click
Virtualization has become an incredibly powerful and flexible way to deploy environments. So much in fact that Microsoft has integrated the ability to attach virtual hard drive (VHD) files as physical disks in the Windows Disk Management tool. This process is easy enough to do manually but if you attach VHD files often then we have a solution which enables you to mount and unmount VHD files with a single click.
Simply add our Mount VHD and Unmount VHD scripts to your Send To menu.
Now whenever you right click on a VHD file, go to the Send To > Mount VHD command. Note: This action will require administrator rights, you may receive a UAC elevated permission prompt.
After the script has run, the VHD is available in Disk Managment and Windows Explorer and can be accessed just like a physical disk.
When you are finished using the VHD, simply unmount it by right clicking on the VHD file and going Send To > Unmount VHD.
The Scripts
Mount VHD
@ECHO OFF
TITLE Mount VHD
ECHO Mount VHD
ECHO Written by: Jason Faulkner
ECHO SysadminGeek.com
ECHO.
ECHO.
SETLOCAL
SET DiskPartScript="%TEMP%DiskpartScript.txt"
ECHO SELECT VDISK FILE="%~1" > %DiskPartScript%
ECHO ATTACH VDISK >> %DiskPartScript%
DiskPart /s %DiskPartScript%
ENDLOCAL
Unmount VHD
@ECHO OFF
TITLE Unmount VHD
ECHO Unmount VHD
ECHO Written by: Jason Faulkner
ECHO SysadminGeek.com
ECHO.
ECHO.
SETLOCAL
SET DiskPartScript="%TEMP%DiskpartScript.txt"
ECHO SELECT VDISK FILE="%~1" > %DiskPartScript%
ECHO DETACH VDISK >> %DiskPartScript%
DiskPart /s %DiskPartScript%
ENDLOCAL
Links
Got Feedback? Join the discussion at discuss.howtogeek.com
Comments (7)
Jason Faulkner is a developer and IT professional who never has a hot cup of coffee far away. Interact with him on Google+
- Published 08/18/10






This became critically usefull for me as windows backup was not able to backup to my external harddrive that I had already backuped to earlier in the month. Once I mounted the backup .vhd file (K:), I was able to refresh the “backup to” list in windows backup and send the backup of all users files and a new system image there!
@geek or jason, I Have a small vhd on a 3rd physical drive and one on an external. This works fine on the usb but will not on the internal. Any suggestions for me?
Donnie – make sure the one you cannot mount is not already mounted elsewhere (i.e. booted up in a VM). A simple test would be to see if you can rename the file.
If that doesn’t help, try manually linking it and see where the process fails and this should give you some insight.
http://tinyhacker.com/hacks/editing-vhd-images-with-windows-7s-disk-management-tool/
Thanks a million! Haha was finding high and low got so scared but ur scripts saved me day!
You have “DiskPart /s %DiskPartScript%” and it needs to be “DiskPart -s %DiskPartScript%” otherwise it fails in Windows 7.
Actually it works fine on Windows 7 with the “/s” switch.
This is the OS I developed the scripts on.
This is better than installing software.
Many thanks…on behalf of my RIPped Vmlite XP Mode which finally
called it a day.