Search notes:

sc.exe

sc.exe is the Service Control Manager Configuration Tool.

Commands

query Queries the status for a service, or enumerates the status for types of services.
queryex Queries the extended status for a service, or enumerates the status for types of services.
start Starts a service.
pause Sends a PAUSE control request to a service.
interrogate Sends an INTERROGATE control request to a service.
continue Sends a CONTINUE control request to a service.
stop Sends a STOP request to a service.
config Changes the configuration of a service (persistent).
description Changes the description of a service.
failure Changes the actions taken by a service upon failure.
failureflag Changes the failure actions flag of a service.
sidtype Changes the service SID type of a service.
privs Changes the required privileges of a service.
managedaccount Changes the service to mark the service account password as managed by LSA.
qc Queries the configuration information for a service.
qdescription Queries the description for a service.
qfailure Queries the actions taken by a service upon failure.
qfailureflag Queries the failure actions flag of a service.
qsidtype Queries the service SID type of a service.
qprivs Queries the required privileges of a service.
qtriggerinfo Queries the trigger parameters of a service.
qpreferrednode Queries the preferred NUMA node of a service.
qmanagedaccount Queries whether a services uses an account with a password managed by LSA.
qprotection Queries the process protection level of a service.
quserservice Queries for a local instance of a user service template.
delete Deletes a service (from the registry).
create Creates a service. (adds it to the registry).
control Sends a control to a service.
sdshow Displays a service's security descriptor.
sdset Sets a service's security descriptor.
showsid Displays the service SID (S-1-5-80-…) that corresponding to an arbitrary name (the service does not have to exist)
triggerinfo Configures the trigger parameters of a service.
preferrednode Sets the preferred NUMA node of a service.
GetDisplayName Gets the DisplayName for a service.
GetKeyName Gets the ServiceKeyName for a service.
EnumDepend Enumerates Service Dependencies.
boot [ok|bat] Indicates whether the last boot should be saved as the last-known-good boot configuration (Does not require a service name)
Lock Locks the Service Database (Does not require a service name)
QueryLock Queries the LockStatus for the SCManager Database (Does not require a service name)

Querying the status of services

The status of a running (active) service can be queried with sc query service-name:
C:\> sc query CryptSvc
        TYPE               : 30  WIN32
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
In order to query all services, sc query state=all is needed. Without state=all, only running (active) services are returned.
C:\> sc query state=all

Insufficient buffer size returned FAILED 122

At times, sc.exe fails with an error message that the buffer size was too small:
C:\Windows\system32>sc qprivs beep
[SC] GetConfigInfo: Insufficient buffer size returned FAILED 122:

The data area passed to a system call is too small.

[SC] GetConfigInfo needs 8 bytes
   … …
So, we specifically add a buffer size to the command: same command, but buffer size of 8 appended (error was GetConfigInfo needs 8 bytes):
C:\Windows\system32>sc qprivs beep 8
[SC] QueryServiceConfig2 SUCCESS


SERVICE_NAME: beep
        PRIVILEGES       :
There's also the bufsize= option, but this does not really seem to work in this case.

PowerShell

Note that PowerShell has an alias sc for set-content. Thus, in order to use sc from a PowerShell command line, it needs to be invoked with its suffix, sc.exe.

sc showsid

sc showsid can be used to show the SID of a service (whose value starts with S-1-5-80-…) of a service (actually of any arbitrary string):
PS:\> sc.exe showsid power
SERVICE SID: S-1-5-80-2343416411-2961288913-598565901-392633850-2111459193
STATUS: Active
C:\> sc showsid trustedInstaller
SERVICE SID: S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464
STATUS: Active

Index