Wildcard with stop / start service

I know we could do this in VBS, PowerShell, etc. However, we don't want to do this with a language other than the good ol package.

Found out the following:

TASKKILL /F /IM "tomcat*"

      

And that will force kill / stop any persistent Tomcat instances. Also, this will cover Tomcat6.exe, Tomcat6_1.exe, tomcat7.exe, etc.

What is my question. We know we can do NET START Tomcat6 for example .. Is it possible:

NET START Tomcat*

      

? Yes, I'm fully aware of the fact that you have multiple Tomcat instances on the server, this will fail as you have to iterate over the list of instances. However, the reason I am looking at this is because I have a monthly script we need to run and I am trying to make the batch script more portable.

Thank.

+3


source to share


2 answers


You can use wildcard WMIC commands to accomplish this:

wmic service where "name like 'tomcat%'" call stopservice

      



See Restarting Wildcard Services on the Superuser Site.

+5


source


@echo off
set "service=tomcat"
for /f "tokens=2 delims=: " %%# in ('sc query type^= service^|find /i "SERVICE_NAME:"^|findstr /i /b /c:"SERVICE_NAME: %service%"') do (
    set "nservice=%%#"
)
echo %nservice%
net start %nservice%

      



this is?

+1


source







All Articles