Hello,
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.
https://learn.microsoft.com/en-us/windows/win32/shutdown/wm-queryendsession
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.
https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-readeventloga
https://learn.microsoft.com/en-us/windows/win32/eventlog/querying-for-event-source-messages
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.
I have improved the above answer based on your questions.
It has been a long time. Have you solved your problem?
Thank you for the follow up. We have not implemented the solution you provides but are planning to do it. I'll will update as soon as it is implemented.
Sign in to comment