lironda
lironda

Reputation: 171

subscribe to windows system events native c++

I want my c++ app to listen to windows system event like, logon, logoff, lock... similar to: http://www.dotnetspider.com/resources/30389-To-detect-when-system-gets.aspx that is written in C#.
I found http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.aspx#Y0m, but its a CLR code. Also, I see that SubscribeToSystemEvent function is in visual C++.

Does anyone know which methods to use in native c++?

please advise,

Liron

Upvotes: 3

Views: 3716

Answers (2)

Rugved Mahamune
Rugved Mahamune

Reputation: 566

You can try krabset https://github.com/Microsoft/krabsetw which is wrapper. You can also check this out https://learn.microsoft.com/en-us/dotnet/api/system.security.accesscontrol?view=netframework-4.7.2

Also look into New-WinEvent and Get-WinEvent by PowerShell

Upvotes: 1

Scotty
Scotty

Reputation: 2510

Call WTSRegisterSessionNotification to receive WM_WTSSESSION_CHANGE window messages when the session state changes. This includes logon, logoff, lock, unlock and others. Make sure you have a corresponding call to WTSUnRegisterSessionNotification before your program exits.

Alternatively, you could listen for WM_QUERYENDSESSION or WM_ENDSESSION window messages. The first allows you to prevent the user from logging off; the second tells you whether it's going to happen.

Upvotes: 5

Related Questions