The code below demonstrates the method for scripting through the restart of a Windows system; you’d do something similar for other operating systems.
-- 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 "false"
try
connect myConnection
-- make sure the machine has really restarted
-- the vnc server seems to spring back to life momentarily during shutdown
RefreshScreen
if not imageFound("StartMenu")
disconnect
next repeat
end if
catch
wait 5.0
end try
end repeat
The Windows OS presented a complication that required a couple of workarounds. The VNC server was running as a service and it seemed to persist into part of the shutdown process. So the connection would be dropped initially, but a reconnect could be made briefly while the machine was shutting down. So to ensure that a successful connection had taken place after the restart, I had to add a visual confirmation that the Start menu was displayed. If it is not, I assume that I’ve reconnected during the shut down, force a disconnect, and return to the beginning of the repeat loop.