Right click to mount vhd files

I have just upgraded my machines to Windows 7 RTM, before I did the reinstall I did full backup of my old Vista machines, of course I figured out that I had not gotten all the files out of the Vista machines before I upgraded, So I had to restore some files from the resulting .vhd backup images. But when I started Windows 7 restore, it did not recognize the backup folders.. So I thought I would just mount the vhd backup files manually, by going into Computer Management -> Disk management. But after having done that a few times, I thought it was too much hassle, so I decided to write a little PowerShell script to mount the vhd files for me.

PowerShell function to create a script file for diskpart

and the execute diskpart with the scriptfile

function Mount-Vhd {param([String]$InputFile)
“SELECT VDISK FILE=""$InputFile”"" + “rn” + “ATTACH VDISK” | Out-File $env:TEMP\Mountvhd.txt -Encoding “ASCII”
Invoke-Expression -Command “Diskpart.exe /s $env:TEMP\Mountvhd.txt”
Mount-Vhd $args[0]
The above script has to be saved as “Mount-vhd.ps1”

But I wanted something even more simple, I just wanted to be able to right-click a .vhd file and choose open, so I created this little .reg file, that will allow you to right click a .vhd file and choose open.

Windows Registry Editor Version 5.00


@=“Open VHD”

[HKEY_CLASSES_ROOT.vhd\shell\Open VHD]
@=“Open &VHD”

[HKEY_CLASSES_ROOT.vhd\shell\Open VHD\command]

When you import the file, all the hex values are converted back to ascii chars, which you can see under [HKEY_CLASSES_ROOT.vhd\shell\Open VHD\command] of course

Here is what will be written:

“C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” -WindowStyle hidden -file “c:\tools\Mount-vhd.ps1” “%1”

As you can see it expects the Mount-Vhd powershell file to be located in C:\tools\ in order to work. I have so far not been able to make it work, without referencing the file directly.

But when you have imported the .reg file, you can just navigate to [HKEY_CLASSES_ROOT.vhd\shell\Open VHD\command] and change the path to anything you like.

You can download both files from here: http://xipher.dk/Tools/ImportVHDsettings.zip

comments powered by Disqus