Automating virtual machines by checking the thumbnail

Automating virtual machines by checking the thumbnail

Rate This
  • Comments 3

One of the biggest challenges with automating virtual machines today is being able to detect that a virtual machine is at a specific place in execution (like waiting at the Windows login screen).  A highly effective way to do this is to do a comparison on the thumbnail image of the virtual machine.  While this is only a 64x48 pixel image it is highly accurate for automation purposes.  Here is a piece of script that will save the thumbnail of a virtual machine to a text file.  Usually the thumbnail data is returned as an array - for convenient storage and comparison the Join() command can be used to turn the thumbnail into a string:

'This script takes three parameters.  The Virtual Server Host, the virtual machine name and
'the file name to store the thumbnail data in.  It then saves the current thumbnail data for
'the selected virtual machine to the specified data file

vsHost = WScript.Arguments(0)
vmName = WScript.Arguments(1)
thumbnailFile = WScript.Arguments(2)

'Connect to Virtual Server
Set vs = CreateObject("VirtualServer.Application", vsHost)

'Find virtual machine
set vm = vs.FindVirtualMachine(vmName)

Wscript.echo "Saving thumbnail data"

'Save thumbnail data
Set objFSO = CreateObject("scripting.filesystemobject")
Set objTextStream = objFSO.OpenTextFile(thumbnailFile, 2, True)
objTextStream.WriteLine Join(vm.Display.Thumbnail)
objTextStream.close

While this script function will load a thumbnail and wait for a match:

'Function to check the for a thumbnail match
Function checkForThumbnailMatch(thumbnailFile)

checkForThumbnailMatch = false

'Open requested thumbnail file
Set objFSO = CreateObject("scripting.filesystemobject")
Set objTextStream = objFSO.OpenTextFile(thumbnailFile, 1, True)
savedThumbnail = objTextStream.ReadLine
objTextStream.close

   'Poll for matching thumbnail
   do until savedThumbnail = Join(vm.Display.Thumbnail)
      wscript.sleep(2000)
   loop

checkForThumbnailMatch = true

end Function

This is very handy - and we have been able to use this internally to automate a variety of things - like complete operating system installations.

Cheers,
Ben

Leave a Comment
  • Please add 3 and 3 and type the answer here:
  • Post
  • Brilliant! That's exactly what I've been needing in my automated install scripts.

    Can't wait to try this out!

    Cheers,
    David
  • Hi, Interesting post. Are there any publsihed guidelines or even better "step-by-step" procedures on how to install an operating system on Virtual PC entirely automatically? Thanks.
  • These thumbnails are freaking cool when you think about it. One reason is spelled out here, and that one can get at it with a program at all. For another ... what if my laptop had a thumbnail on the outside case? Maybe a little larger and I could interact with it?
Page 1 of 1 (3 items)