Yes, you are correct Barry, the script is executed before it disconnects.
Steve - if you have an ASCOM switch device, a script to turn a relay on and off can be very simple
set c = CreateObject("ASCOM.Utilities.Chooser")
id = c.Choose("")
set sw = CreateObject(id)
sw.Connected = true
sw.SetSwitch x, y
sw.Connected = false
msgBox "Press OK to continue"
x is the switch number and y is true or false. If you know the device name beforehand, you do not need the prompt to choose it and simply write the name of the ASCOM switch device in the place of id and cut out the ASCOM.chooser line.
Of course you can make it more fancy too. I bought a USB-controlled 4-way relay module from KMTronic. It is controlled with serial commands. I wrote a simple ASCOM driver for it. I can help you with further details if you want. I have this module switching 12V supplies to mount, fans, focuser and camera. To reset the PC, I need something that is independent, for which I use a KMTronic Web relay, that connects to my LAN. In this way, I can cycle the power to the PC and USB hub from any device.