Coding Corner: Compacting a disk part II

On Tuesday I posted some information about creating a ‘disk compaction’ script (http://blogs.msdn.com/virtual_pc_guy/archive/2005/02/08/369509.aspx).  Today I am going to explain how to hook this script up with all your virtual hard disks directly from explorer.  This is actually surprisingly simple.  All you need to do is to copy the following into a text file (note – you will need to change the path for the VBscript appropriately for your system):

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOTVirtual.Machine.HDshellCompactcommand]
@=”cmd /c cscript.exe /nologo “C:\temp\compact.vbs” “%1″”

Rename the text file to ‘compact.reg’ and then double click on the file.  This will import the above registry fragment – which will allow you to now select ‘compact’ off of the right mouse button menu on any virtual hard disk – like this:

Coding Corner: Compacting a disk part II

   Coding Corner: Compacting a disk part II

Cheers,
Ben

UPDATE:  I have been contacted by a couple of people about this post.  It turns out that the registry fragment above only works if you have both Virtual PC and Virtual Server installed on your system (like I do).  If you only have Virtual Server installed – you will need to use this registry fragment:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOTVirtual.Machine.HDshellCompactcommand]
@=”cmd /c cscript.exe /nologo “C:\temp\compact.vbs” “%1″”

[HKEY_CLASSES_ROOT.vhd]
@=”Virtual.Machine.HD”