Это должно сработать (или, по крайней мере, дать вам начало):
@echo off
setlocal
if "%~1"=="" goto usage
set tmpFile=templist.txt
set tmpAnsi=templist_ansi.txt
wmic /locale:MS_409 service where "caption like '%~1' and state='Running'" get caption /format:csv >%tmpFile%
REM this is required to convert from Unicode(UCS-2) to ANSI
type %tmpFile%>%tmpAnsi%
Echo ---------------Stopping services----------------------
Echo.
for /f "tokens=2 skip=2 delims=," %%i in (%tmpAnsi%) do (
wmic /locale:MS_409 service where caption="%%i" call stopservice
)
Echo --------------Starting services-----------------------
Echo.
for /f "tokens=2 skip=2 delims=," %%i in (%tmpAnsi%) do (
wmic /locale:MS_409 service where caption="%%i" call startservice
)
goto end
:usage
Echo.
Echo Usage is:
Echo %~n0 pattern_to_check
Echo.
Echo Pattern:
Echo [ ] Any one character within the specified range ([a=f]) or set ([abcdef]).
Echo ^^ Any one character not within the range ([^a=f]) or set ([^abcdef].)
Echo %% Any string of 0 (zero) or more characters
Echo _ (underscore) Any one character. Any literal underscore
Echo used in the query string must be escaped by placing it inside []
Echo.
Echo If pattern contains spaces, it must be enclosed in double quotes
:end
Если вы назовете свой пакетный файл batch.bat, вы бы назвали его batch.bat "MyServiceFactory -%"
.