The logoff event happens because you're not using BREAK ON in the beginning of your script. See the KiXtart Manual for more info.

Also, put a DEBUG ON into the first line of your script to identify the failing line in your code.

Alternatively, try the fnWMILoggedIn() UDF if you have WMI available.
_________________________
There are two types of vessels, submarines and targets.