An easy way to do this would be something like below.

 Code:
...
$Form.Closing = "DoLogOff()"
...


With this function in your script
 Code:
Function DoLogoff()
	Sleep 0.5
	$Form.close
	$rc = LogOff(1)
EndFunction


There is a more clean way so you just cancel the close event triggered by the top right X but I can't find it right now. Used it once but don’t know where anymore.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.