views:

114

answers:

1

How can I check the existence of a windows service in a batch file?

The user is inputing a service name and I want to check that the service does exist before continuing with my script.

+1  A: 

Try this:

>NET START | FIND "Workstation"

where "Workstation" is the name of the service

IMHO
I'm doing something like the user inputs the service name. But before I continue with my script. I want to make sure that the service he entered is valid. I don't want to start the service ....
pdiddy
then you replace "Workstation" with parameter and save the result of this command in a variable. Then check if it's empty
IMHO
Careful when whatever you're looking for might appear *within* the name of another service.
Joey
how do I store the result into a variable? Sorry I'm not a batch file guru.
pdiddy
Ok I found it with For /F "Tokens=2" %%I in ('<any command>') Do Set <variable name>=%%I
pdiddy