Figure 1   Using Common Tester Objects


 ' A mininal WSH Tester example.  It just starts Notepad, says a few
 ' things and closes Notepad.
 
 ' Get the system and input objects.
 dim tSystem
 dim tInput
 dim tWin
 set tSystem = WScript.CreateObject ( "Tester.TSystem" )
 set tInput = WScript.CreateObject ( "Tester.TInput" )
 
 ' Start notepad.
 tSystem.Execute "NOTEPAD.EXE"
 
 ' Wait 200 milliseconds.
 tSystem.Pause 200
 
 ' Try and find the Notepad main window.
 set tWin = tSystem.FindTopWindowByTitle ( "Untitled - Notepad" )
 if ( tWin is nothing ) then
     MsgBox "Unable to find Notepad!"
     Wscript.Quit
 end if
 
 ' Ensure that Notepad is in the foreground.
 tWin.SetForegroundTWindow
 
 ' Say something
 tInput.PlayKeys "Be all you can be!~~~"
 ' Play it again, Sam.
 tInput.PlayKeys "Put on your boots and parachutes....~~~"
 ' Third time is a charm.
 tInput.PlayKeys "Silver wings upon their chests.....~~~"
 
 ' Wait 1 second.
 tSystem.Pause 1000
 
 ' End notepad.
 tInput.PlayKeys "%FX"
 tSystem.Pause 50
 tInput.PlayKeys "{TAB}~"
 
 ' Script is done!

Figure 2   TNotify in a WSH Script

 
 ' Another WSH script to show the window notification handlers.
 
 ' You can run this one at the same time as Handler.vbs so that you
 ' can see multiple scripts handling notifications at the same time.
 
 ' Constants for the TNotification.AddNotification routine.  If this were
 ' Visual Basic 6.0, I would just use the enums.
 const antDestroyWindow    = 1
 const antCreateWindow     = 2
 const antCreateAndDestroy = 3
 
 const ansExactMatch       = 0
 const ansBeginMatch       = 1
 const ansAnyLocMatch      = 2
 
 
 ' The notification variable.
 dim Notifier
 ' Create the notification handler.  Notice the "_" on the second
 ' parameter to CreateObject.  You need that to get events hooked up
 ' in WSH.
 set Notifier = _
         WScript.CreateObject ( "Tester.TNotify"       , _
                                "NotepadNotification_"     )
 
 ' Add the notifications that I want.  For this demo, I want both destroy
 ' and create.  See the TNotify object for all the gyrations.
 Notifier.AddNotification  antCreateAndDestroy , _
                           ansAnyLocMatch      , _
                           "Notepad"
 
 MsgBox "Ho humm, waiting around for notifications from Windows with
 'Notepad' in their title.  Press OK to end this script!"
 
 ' Disconnect the notifications.  If you don't do this in WSH, the class
 ' terminate never gets called so the notification is still active in the
 ' notification table.
 WScript.DisconnectObject Notifier
 
 set Notifier = Nothing
 
 
 
 sub NotepadNotification_CreateWindow ( tWin )
     WScript.Echo ( "Multiple watch reports : A window with Notepad in the caption 
 was created!!" )
 end sub
 
 sub NotepadNotification_DestroyWindow ( )
     WScript.Echo ( "Multiple watch reports : A window with Notepad in the caption 
 has gone away...." )
 end sub