Capturing a Hyper-V VM Screen to a file

Here is an interesting thing you can do with Hyper-V – with a little bit of code you can grab a copy of the virtual machine display and write it out to a bitmap file:

This is something that I use in a number of my long running scripts – as it provides a very handy logging trail if something goes wrong.  Something to note about this code: I use MSVM_VideoHead to get the resolution of the virtual machine display – and then hand that into GetVirtualSystemThumbnailImage.  You can also provide smaller dimensions than the current virtual machine display – in which case we will scale the bitmap image down for you.

Which is where this API gets its name from “GetVirtualSystemThumbnailImage” is actually used by Hyper-V Manager to generate the thumbnail image from the virtual machine.  It just also happens to support generating full resolution images as well.

Cheers,
Ben