Microsoft’s Virtual PC Guy (Ben Armstrong) wrote a blog post last year about using the VHDMount utility from Virtual Server 2005 R2 SP1 with a few registry edits to enable right-click mounting/dismounting of virtual hard disk (.VHD) files.
As .VHD files become ever more prevalent, this is a really useful capability (for example, Windows Vista’s Complete PC Backup functionality writes to a .VHD file).
The trouble is that, as supplied, Ben’s script does not work on Windows Vista as attempting to run vhdmount.exe will return:
Access Denied. Administrator permissions are needed to use the selected options. Use an elevated command prompt to complete these tasks.
An elevated command prompt is fine for entering commands directly (or by running a script) but what about Ben’s example of providing shell-integration to mount .VHDs from Explorer? Thankfully, as Steve Sinchak noted in TweakVista, Michael Murgolo wrote an article about elevating commands within scripts using a free PowerToy called elevate which is available from the Microsoft website. After downloading and extracting the elevate PowerToy scripts, I was able to confirm that they would let me run vhdmount.exe using the command elevate vhdmount.exe
Following that, I edited Ben Armstrong’s registry file to read:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell]
@="Mount"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell\Dismount]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell\Dismount\command]
@="\"C:\\Program Files\\Script Elevation PowerToys\\elevate\" \"C:\\Program Files\\Microsoft Virtual Server\\Vhdmount\\vhdmount.exe\" /u /d \"%1\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell\Mount]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell\Mount\command]
@="\"C:\\Program Files\\Script Elevation PowerToys\\elevate\" \"C:\\Program Files\\Microsoft Virtual Server\\Vhdmount\\vhdmount.exe\" /p \"%1\""
[HKEY_CLASSES_ROOT\.vhd]
@="Virtual.Machine.HD"
Note the /d switch in the dismount command. I had to use this (or /c) to allow the disk to be unmounted and avoid the following message:
The specified Virtual Hard Disk (VHD) is plugged in using the default Undo Disk option. Use /c to commit or /d to discard the changes to the mounted disk.
I chose the discard option as most of my .VHDs mounting is simply to extract files but others may prefer to commit.
A few more points to note about VHDMount:
- VHDMount is an installable option in the Virtual Server 2005 R2 SP1 setup program (I installed it together with the virtual machine remote control (VMRC) client on my Vista client PC as I find the VMRC client to be much more responsive than managing VMs through a web browser).
- Earlier versions of VHDMount did not use a signed driver, resulting in an error that says the device driver software was not successfully installed. The release version of the driver is signed.
- If you try to expand a virtual hard disk beyond the limits of the physical hardware (e.g. copy a large file to a mounted volume), it will probably hang your system (pretty obvious really but see Microsoft knowledge base article 937366 for more details).
- The VHD_MOUNT_TRACE environment variable can be used for troubleshooting issues with VHDMount.
Leave a Reply