You can use sc
to ask for configuration information ( qc
, query configuration ) of a service:
qc: Queries the configuration information for a service.
qc: Check the configuration information of a service.
Example of use:
C:\Windows\system32>sc qc AppMgmt
[SC] QueryServiceConfig SUCCESS
SERVICE_NAME: AppMgmt
TYPE : 20 WIN32_SHARE_PROCESS
START_TYPE : 3 DEMAND_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : C:\Windows\system32\svchost.exe -k netsvcs
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : Application Management
DEPENDENCIES :
SERVICE_START_NAME : LocalSystem
As you can see, it has a manual start ( DEMAND_START
).
Example in which I check the boot mode and the status of the service:
@echo off
sc qc %1 | find "AUTO_START" > NUL
if not errorlevel 0 goto fin
sc query %1 | find "STOPPED" > NUL
if not errorlevel 0 goto fin
echo Arrancando el servicio %1
sc start %1
:fin
echo Trabajo finalizado
First I check if it is automatic start ( AUTO_START
), in any other case I finish the execution.
If it is an automatic start service I check if it is in the stopped state ( STOPPED
), in any other case I finish the execution (eye, it could be in the state PAUSED
, PAUSE_PENDING
, CONTINUE_PENDING
, START_PENDING
or STOP_PENDING
.
In the end, if the service is configured for automatic start and is stopped, the boot is ordered.