views:

95

answers:

5

Hello,

I need to catch windows logoff event, I'm using c++. I dont know where to start searching,

thanks for any help,

Dani.

A: 

This might help you.

thelost
Involving .NET just to catch the log-off event is a bad solution.
adf88
Involving .NET is a bad solution.
Vulcan Eager
high overhead for something simple and available
seand
+4  A: 

WM_QUERYENDSESSION and WM_ENDSESSION are most likely what you're after.

Will A
+6  A: 

In console application, you can register a callback (SetConsoleCtrlHandler, CTRL_LOGOFF_EVENT).

In message-loop application, you can catch certain messages (WM_QUERYENDSESSION, WM_ENDSESSION).

See Logging Off (Windows) on MSDN.

adf88
A: 

I believe the "correct" way is to listen to a WMI event.

http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/0c1bded8-0cce-4260-bd28-4b4ffce0d27d

Disclaimer: I have not tried this myself.

Vulcan Eager
+1  A: 

You can use OpenInputDesktop MSDN

During logoff, the Input Desktop is inaccessible to the user, and the function retuns NULL.

ex: HDESK hDesk = OpenInputDesktop(0, FALSE, READ_CONTROL);

if (!hDesk) -- during logoff... -- else { --normal state-- CloseHandle(hDesk); }

In windows vista & 7, pressing CTRL+ALT+DELETE also brings to an inaccessible to the user desktop.

vdk