well.... I'd have my main process thread (which is a UI thread with a message pump) create a new handle (global) at startup, then hook the log-off event, when the log-off occurs, set your global...