group=
groupname
Query services
in a particular group
Misc commands that don’t require a service name:
SC QueryLock Query the LockStatus for the ServiceManager
Database.
this will show if a service request is running
SC Lock
Lock the Service Database
SC BOOT Values are {ok | bad} Indicates whether to
save
the last restart configuration as the `last-
known-good`
restart configuration
Options
The CREATE and CONFIG commands allow additional
options to be set
see the build-in help: 'SC create' and 'SC config'
Note the
qryOpt
options above are case sensitive - they must be entered in lower case, also
the position of spaces and = must be exactly as shown.
The SC command duplicates some aspects of the
NET
command but adds
the ability to create a
service.
SC query will display if a service is running, giving output like this:
SERVICE_NAME : messenger
TYPE : 20 WIN32_SHARE_PROCESS
STATE : 4 RUNNING
(STOPPABLE,NOT_PAUSABLE,ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
To retrieve specific information from SC's output,
pipe
into
FIND
or
FindStr
e.g.
C:\> SC query messenger | FIND "STATE" | FIND "STOPPED"
C:\> SC query messenger | FIND "STATE" | FIND "RUNNING"
The statements above will return an %ERRORLEVEL% = 1 if the text is not found
IF errorlevel 1 GOTO :my_subroutine
The
NET
START command can be used in a similar way to check if a service is running:
NET START | FIND "Service name" > nul
IF errorlevel 1 ECHO
The service is not running
The service control manager will normally wait up to 30 seconds to allow a service to start - you
can modify this time (30,000 milliseconds) in the registry
HKLM\SYSTEM\CurrentControlSet\Control
ServicesPipeTimeout (REG_DWORD)
Some options only take effect at the point when the service is started e.g. the
SC
config
command allows the executable of a service to be changed. When the service next
starts up it will run the new executable. Config changes requires the current user to have
“permission to configure the service”.
Chia sẻ với bạn bè của bạn: