Movatterモバイル変換


[0]ホーム

URL:


SC.exe

Service Control - Create, Start, Stop, Query orDelete any WindowsSERVICE. The commandoptions for SC are case sensitive.

Syntax      SC [\\server] [command] [service_name] [Options]Keyserver       : The machine where the service is runningservice_name : The KeyName of the service, this is often but not always                  the same as the DisplayName shown in Control Panel, Services.                  You can get the KeyName by running:                      SC GetKeyNameDisplayNamecommands:query  [qryOpt]   Show status.          queryEx [qryOpt]  Show extended info - pid, flags.          GetDisplayName    Show the DisplayName.          GetKeyName        Show the Service KeyName.          EnumDepend        Show Dependencies.          qc                Show config - dependencies, full path etc.start          START a service.stop           STOP a service          pause          PAUSE a service.          continue       CONTINUE a service.          create         Create a service. (add it to the registry).config         permanently change the service configuration.          delete         Delete a service (from the registry).          control        Send a control to a service.          interrogate    Send an INTERROGATE control request to a service.          Qdescription   Query the description of a service.          description    Change the description of a service.          Qfailure       Query the actions taken by a service upon failure.          failure        Change the actions taken by a service upon failure.          sdShow         Display a service’s security descriptor using SDDL.          SdSet          Sets a service’s security descriptor using SDDL.qryOpt:          type= driver|service|all                         Query specific types of service.          state= active|inactive|all                         Query services in a particular state only.          bufsize=bytes           ri=resume_index_number (default=0)          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 service options to be set     e.g. to disable a service: SC config "Name of Service" start= disabled     see the built-in help for more: 'SC create' and 'SC config'

TheqryOpt options above are case sensitive, they must be entered in lower case, also the position of spaces and = must be exactly as shown.

Kernel device drivers are not displayed in the Windows Control Panel Services but can be displayed by SC.

The SC command duplicates some aspects of theNET command but adds the ability to create a service.

Query a Service state

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 intoFIND orFindStr
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

TheNET 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

Watch out for extra spaces:
SC QUERY state= allWorks
SC QUERY state =allFails!

Start a Service

Start the schedule service:

SC start schedule

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. theSC 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”.

PowerShell

Like every otherexternal command SC can be run under PowerShell instead of CMD, however there is one extra complication for SC and that is the standard PowerShell alias SC which redirects to theSet-Content cmdlet.

To avoid that, use thecall operator to run SC.exe from PowerShell:

& sc.exe

Examples

SC GetKeyName "task scheduler"SC GetDisplayName scheduleSC start scheduleSC QUERY scheduleSC CONFIG "Schedule" start= disabledSC QUERY type= driverSC QUERY state= all |findstr "DISPLAY_NAME STATE" >svc_installed.txt SC \\myServer CONFIG myService obj= LocalSystem password= mypasswordSC CONFIG MyService binPath=c:\myprogram.exe obj=".\LocalSystem" password=""

Disable Windows Update (Windows 10)

SC config wuauserv start= disabledNET stop wuauservSC config bits start= disabledNET stop bitsSC config dosvc start= disabledNET stop dosvc

To re-enable Windows Update set the'start=' back to 'auto' andstart the services.

Enable remote registry access on computer64:

SC \\computer64 config remoteregistry start= autoSC \\computer64 start remoteregistry

“There is always room at the top” ~ Daniel Webster

Related commands

DELSRV - Delete a service.
INSTSRV - Install a service (run under a specific account).
NET - manage network resources.
PsService - View and control services.
Svcmon - Monitor services and raise an alert if they stop. (Win 2K ResKit)
SUBINACL - Set service permissions.
WMIC SERVICE - WMI access to services.
Win32_Service class error return codes.
List of Windows Services
Q251192 - Create a Windows Service using SC.
Q166819 - Control Services Remotely.
Q170738 - Debug a Windows Service.
Equivalent PowerShell:Get-Service - Get a list of services /Invoke-CimMethod - start/stop services via CIM.
Equivalent bash command (Linux):nice - Change job scheduling priority.


 
Copyright © 1999-2026SS64.com
Some rights reserved

[8]ページ先頭

©2009-2026 Movatter.jp