logo
logo
AI Products 
Leaderboard Community🔥 Earn points

Handling the OS shutdown event using WinAPI

avatar
Dennis Turpitka
collect
0
collect
0
collect
1
Handling the OS shutdown event using WinAPI

This guide will cover certain ways to detect restart or shutdown of the PC, as well as other similar events, such as log off or sleep.

Our function analyzes input parameter data, decides which event has occurred and executes certain code as a response to this event.

In order to catch shutdown event in a console application, we should start by creating our own handler function:

BOOL WINAPI HandlerRoutine(_In_ DWORD dwCtrlType);

Next, register it as a handler for this console application by using the following API function:

BOOL WINAPI SetConsoleCtrlHandler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine, _In_ BOOL Add);

collect
0
collect
0
collect
1
avatar
Dennis Turpitka