I have a c#(.net) windows service that needs to do something either when windows startup or when user logged in(including back from hibernate). how can the service detect this? any windows events specific for it?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
- Inheritance impossible in Windows Runtime Componen
For windows startup check the easeist way to use Environment.TickCount, and probably you need to save some previous windows startup values into config and compare with them.
When Environment.TickCount is not enough for you or very easy :) Then use WMI:
To detect log-on/log-off as it was said in one of comments use SystemEvents class, and event SessionSwitch.
Please note that it works only if the message pump is running. In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised.