When using the following command to return information about a service to a file :
sc.exe query MyService >> MyFileLocation\MyFile.txt
I get the following information in the file :
SERVICE_NAME: MyService
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
But I only need the State. I have checked the properties in the docs :
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/sc-query
But I can't find anything that lets me return only the state. Is it possible to do and if so how to do it? Thanks in advance.