How would one go about using WMI to start, stop, and query services on the local computer from .NET code? (I’m using C#)
I have found good and accurate answers for using the ServiceController class to do this, but I’d like to use WMI if I can.
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.
If you wish to use WMI over the more intuitive
ServiceControllerclass, see this article (excuse the color scheme, but it has what you want).Sample code (error handling here is bit hard-coded for my taste):