问题
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