Virtual Server exposes a number of interesting events which you may want to use to initiate appropriate actions.  However, detecting these events with VBScript is not entirely intuitive.  Below is a script that will listen for the first virtual machine state change event and then tell the user the name of the virtual machine for which the event occurred (state change refers to any action like power on, turn off, save state, etc...)

Option Explicit

Dim vs, alive

'Jump to the main routine



sub keepAlive()

' This subroutine makes sure that the script hangs around in order
' to capture any Virtual Server events

while (alive = 1) 

end sub


Sub vs_OnVMStateChange(vmConfig, vmState)

   wscript.echo vmConfig

   alive = 0

end sub


sub main()

   alive = 1

   'Create Virtual Server COM object and indicate that all subroutines
'that begin with "vs_" are event handlers

   Set vs = WScript.CreateObject( "VirtualServer.Application" )
WScript.ConnectObject vs, "vs_"


end sub


As you can see a couple of things are needed:

  1. You need a 'keep alive' loop to make sure that the script doesn't exit before the event fires.

  2. You need to use WScript.ConnectObject to associate Virtual Server events with a specific prefix.  In this sample I use the 'vs_' prefix.  This way whenever any event fires this script will check to see if it has a subroutine of form 'vs_EVENTNAME' - and if it has that subroutine it will run it.  Details on all of the events that Virtual Server exposes can be found in the Virtual Server Programmers Guide.