Handling Microsoft virtual machines events with VBScript

This is nice: Ben Armstrong just posted on his blog a new script for getting events from Virtual Server VMs with VBScript:

Option Explicit

Dim vs, vm, alive

‘Jump to the main routine

main()

‘============================’

sub keepAlive()

‘ This subroutine makes sure that the script hangs around
‘ in order to capture any server events

On Error Resume Next

while (alive = 1)
WScript.Sleep(500)
wend

end sub

‘============================’

Sub vm_OnStateChange(vmState)

wscript.echo vmState

alive = 0

end sub

‘============================’

sub main()

alive = 1

Set vs = WScript.CreateObject( “VirtualServer.Application” )

set vm = vs.FindVirtualMachine(“My Test Virtual Machine”)

WScript.ConnectObject vm, “vm_”

keepAlive()

end sub

‘===========================’