Skip to main content

Scripting through a SUT Restart

A question that comes up from time-to-time is the need to run a script that restarts the system under test (SUT). The code referenced below demonstrates the method for scripting through the restart of a Windows system. You’d do something similar for other operating systems.

Step by Step: Scripting through a SUT Restart

The process has several steps:

  1. Store the current connection information to use as the argument to the connect command after the restart.
  2. Script the restart.
  3. Wait for the restart to finish.
  4. Reconnect to the system.

Windows presents a complication that requires a couple of workarounds. The VNC server runs as a service and seems to persist into part of the shutdown process. So the connection will drop initially, but a reconnect could be made briefly while the machine was shutting down. So to ensure that a successful connection takes place after the restart, it’s a good idea to add a check for a visual cue to see that the restart is finished. If it is not, assume that you’ve reconnected during the shutdown, force a disconnect, and start the check over again.


-- store the current connection information to use as the argument to the connect command later
put connectionInfo() into myConnection
-- do restart here
repeat while connectionInfo().connected is "true"
-- make sure the connection has been closed by the remote system
wait 1
end repeat
-- now try to reconnect
repeat while connectionInfo().connected is not "true"
connect myConnection
-- make sure the machine has really restarted
-- the vnc server seems to spring back to life momentarily during shutdown
if not imageFound("StartMenu")
next repeat
end if
wait 5.0
end try
end repeat