How do i catch system Logoff/ShutDown/Lock events in Python or PyQt4

随声附和 提交于 2021-02-08 08:20:28

问题


I have an application in .NET now i am recoding it using Python and PyQt. In my application i need to know system events (Lock,Logoff,Restart and Shutdown). I could able to manage it from .NET Frame work 3.5 using below snippit

AddHandler SystemEvents.SessionEnding, AddressOf ClosingApplication
AddHandler SystemEvents.SessionSwitch, AddressOf SessionSwitchEvent

Depending on the system i need to do some stuff to update my Database.

Can any one help me plz...


回答1:


You are going to need to use the pywin32 library. It is a wrapper class for the win32api. You can then use the SetConsoleCtrlHandler to catch the signal.

To cleanly capture the signal you are going to need to spawn a console window. To make your application run cleanly, you can run the console window in a hidden state. For more information about how to spawn the console window see: Python - Windows Shutdown Events



来源:https://stackoverflow.com/questions/13703887/how-do-i-catch-system-logoff-shutdown-lock-events-in-python-or-pyqt4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!