Handling virtual machine events from VBScript
A couple of weeks ago, I posted a sample script to handle Virtual Server events (here: https://blogs.msdn.com/virtual_pc_guy/archive/2005/11/03/488301.aspx). Well today I have a slightly different script that shows you how to get events for a specific virtual machine:
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 eventsOn Error Resume Next
while (alive = 1)
WScript.Sleep(500)
wendend 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
'================================================================'
As you can see - it is mostly the same - except for the fact that I create the connection with the virtual machine instance, rather than the Virtual Server instance.
Cheers,
Ben