Hi @Sachin Kumar ,Welcome to Q&A.
This is possible, you need to refer to WM_QUERYENDSESSION message and SystemEvents.SessionEnding Event.
You can also Use OnShutdown to specify the processing that occurs when the system shuts down.
This following case can give a good example of your problem.
Best Regards, Jiale
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.