Another option :)
@echo off for /f "delims=" %%A in ( 'wmic service where "name='themes' and state='running'" get' ) do for /f "delims=" %%B in ("%%A") do echo %%B
Complex WHERE clauses must be either quoted or enclosed in brackets. Additional internal ' does not cause problems with FOR / F.
I added extra FOR / F to cut out the unnecessary carriage return, which is added to the end of each line as an FOR / F artifact that converts WMIC unicode output to ANSII. Without additional FOR / F, there is an additional line consisting solely of a carriage return, which leads to the end of ECHO is off. in the end.
I think I prefer the jeb version because it eliminates the need for escape in the whole command, although I would probably use single quotes in the WHERE clause. For instance:
@echo off for /f "delims=" %%A in ( '"wmic service where (name='themes' and state='running') get name, pathName"' ) do for /f "delims=" %%B in ("%%A") do echo %%B
Using syntax in my first code example requires escaping commas in a GET clause:
@echo off for /f "delims=" %%A in ( 'wmic service where "name='themes' and state='running'" get name^, pathName' ) do for /f "delims=" %%B in ("%%A") do echo %%B
source share