How to logoff a user when the workstation is locked?

781 views Asked by At

I wrote a Windows application that comes with two modules: service and user-mode applications. The service implements its own scheduler and may log-off a user at a predefined time. For that I was using the following call that is triggered from my user-mode module running in a logged-on user session that has to be logged off:

BOOL result = ExitWindowsEx(EWX_LOGOFF, reason);

This works fine, except of the situation when a user's account is locked. In that case that API doesn't seem to do anything at all even through I get 1 returned from it.

So I was curious, is there any other way to log off a user when their account is locked? (One condition I have in this case is that if that user had any unsaved documents then the log-off should not be forced.)

1

There are 1 answers

2
user2120666 On

Try this:

DWORD dFlags = EWX_LOGOFF | EWX_FORCE | 0x10200;

BOOL result = ExitWindowsEx(dFlags, reason);