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.
Hello,
Running Vista and I can’t import your modified Ben Armstrong .reg file into the registry. I get an error “Cannot import vhdmount.reg. Error accessing the registry”.
What am I doing wrong?
Hi Ted – are you using the elevate PowerToy? If so, has someone locked down the registry in some way? HTH, Mark
Hi,
I installed the Powertoys by extracting and installing the .inf files. However, the directory “C:\\Program Files\\Script Elevation PowerToys\\elevate\” that your file points to does not seem to exist. The elevate.cmd and elevate.vbs files exist only in my download directory where I extracted them. Is there a trick to installing this powertoy? Do I have to manually create this directory? This may very well be the problem.
Hi Ted
Sorry, I should have been clearer – C:\Program Files\Script Elevation PowerToys\elevate is the location that I extracted the PowerToys too (there is no installation process as such). You can edit the .reg file to use any path you like as long as you remember to use \\ instead of \ or alternatively you could extract the PowerToy files to the location that I used.
Cheers, Mark
Thanks Mark,
I tried this without success. I think there’s something wrong with the permissions in my registry.
For example, the key [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD]
exists, but in regedit I cannot look at it. It says there is an error opening it and “access is denied”. I’m guessing I can’t import to a key like this?