How would you check if a WIN32 service exists and, if so, do some operation?
Share
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.
Off the top of my head, you can check if a specific service is running, as mentioned by bmargulies, using the “net” command, piping the result into “find”.
Something like the following would check if a service was running, and if so stop it. You can then start it without worrying about if it was already running or not:
If you’re using findstr to do a search, as some of the other answers have suggested, then you would check for ERRORLEVEL equal to 0 (zero)… if it is then you have found the string you’re looking for:
Essentially most DOS commands will set ERRORLEVEL, allowing you to check if something like a find has succeeded.