How can I detect whether the user is logging off?

Raymond Chen

There may be cases where you want to know whether the user is logging off. For example, your program might be responding to external events by (say) launching a helper program, but you don’t want to do that if a logoff is in progress.

The way to find out is hidden in the Get­System­Metrics function, which is admittedly a rather non-obvious place to put it.

if (GetSystemMetrics(SM_SHUTTINGDOWN)) {
 // user is logging off, don't start anything new
}

Compounding the confusion is that the flag is called “shutting down”, but in fact it reports whether the user is logging off (which in today’s parlance is called signing out). The logout may be part of a shutdown, or it might not.

0 comments

Discussion is closed.

Feedback usabilla icon