I wonder if there is any possible way to get or create an event for a status changed of a Windows Service.
I know that the ServiceController class does not have the event, but it has the status. Is there any way that I can listen to an event?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is exactly what the
NotifyServiceStatusChangefunction is intended for. The docs say that it:I’m not sure if there’s an equivalent event wrapped in managed code, but this one is easy enough to get at using P/Invoke.
However, note that this function is only available in Windows Vista and later. If you need to target earlier versions, you can find a solution in one of the answers to this question.