-- Ben Armstrong, Virtualization Program Manager
Talking about core virtualization at Microsoft (Hyper-V, Virtual PC and Virtual Server).
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 ServerSet vs = CreateObject("VirtualServer.Application", vsHost) 'Find virtual machineset vm = vs.FindVirtualMachine(vmName) Wscript.echo "Saving thumbnail data" 'Save thumbnail dataSet objFSO = CreateObject("scripting.filesystemobject")Set objTextStream = objFSO.OpenTextFile(thumbnailFile, 2, True)objTextStream.WriteLine Join(vm.Display.Thumbnail) objTextStream.close
'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 ServerSet vs = CreateObject("VirtualServer.Application", vsHost)
'Find virtual machineset vm = vs.FindVirtualMachine(vmName)
Wscript.echo "Saving thumbnail data"
'Save thumbnail dataSet 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 matchFunction checkForThumbnailMatch(thumbnailFile) checkForThumbnailMatch = false 'Open requested thumbnail fileSet objFSO = CreateObject("scripting.filesystemobject")Set objTextStream = objFSO.OpenTextFile(thumbnailFile, 1, True)savedThumbnail = objTextStream.ReadLineobjTextStream.close 'Poll for matching thumbnail do until savedThumbnail = Join(vm.Display.Thumbnail) wscript.sleep(2000) loop checkForThumbnailMatch = true end Function
'Function to check the for a thumbnail matchFunction checkForThumbnailMatch(thumbnailFile)
checkForThumbnailMatch = false
'Open requested thumbnail fileSet objFSO = CreateObject("scripting.filesystemobject")Set objTextStream = objFSO.OpenTextFile(thumbnailFile, 1, True)savedThumbnail = objTextStream.ReadLineobjTextStream.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