Detect windows logout in Python

后端 未结 2 933
梦毁少年i
梦毁少年i 2021-02-06 12:41

How can I detect, or be notified, when windows is logging out in python?

Edit: Martin v. Löwis\' answer is good, and works for a full logout but it does not work for a \

2条回答
  •  生来不讨喜
    2021-02-06 13:02

    In a console application, you can use win32api.SetConsoleCtrlHandler and look for CTRL_LOGOFF_EVENT. In a GUI application, you need a window open and wait for the WM_QUERYENDSESSION message. How precisely that works (and if it works at all) depends on your GUI library.

提交回复
热议问题