USB device and Windows shutdown

ssalmi 1 Reputation point


I am using a USB device that works like a USB keyboard connected to a USB port of PC or laptop. The USB device powered separately and the PC USB port is not providing the power to the USB device. .
I'd like to let the USB device know when Windows is shutting down on the PC or laptop.
Is there any messages, during Windows shut down, sent to the USB port that the USB device can be listening on?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,449 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Junjie Zhu - MSFT 15,836 Reputation points Microsoft Vendor

    Welcome to Microsoft Q&A!

    Windows shutdown will send WM_QUERYENDSESSION message to all programs, programs receive this message will automatically exit, your program if running will receive this message, as long as the program intercept the message and process.
    So you can intercept to this message in the program and send Windows shutdown Message to your USB device via port.

    About “How to distinguish shutdown between restart,” need access to system logs.
    You can use ReadEventLog to read the System log when WM_QUERYENDSESSION, You can refer to this Querying for Event Information sample.

    Thank you.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.