CMD command to manually, automatically start, and disable services

Source: Internet
Author: User

Use the CMD command to manually, automatically start, and disable services
TIPS: use command line to start the service

You can open the service in cmd in two ways: net, SC, and net. The syntax is as follows:
Net start service name start Net start service name
Stop net stop service name
Net stop service name

(Service name: Right-click the service -- Property -- General -- service name, rather than the display name)

Use SC to enable the disabled service. Syntax:
SC config service name start = demand // manually
SC condig service name start = auto // automatic
SC config service name start = disabled // disable
SC start service name
SC stop service name
Note: 1) the service name is not necessarily the one you see on the service panel. For example, if you want to enable the disabled Telnet service, SC config Telnet start = auto, an error is returned: [SC] openservice failed 1060. Because the telnet service name is not Telnet but TlntSvr, SC config TlntSvr start = auto is OK. Check the Telnet attribute in the service panel, you can see the service program name in the path of the executable file, that is, the service name in the command.
2) Start = There is a space behind it. If it is missing, it will be wrong.

SC .exe command function list: Note: The following command is in progress. = There is a space behind the sign, = There is no space before it!

1. Change the service startup status (this is a useful feature)

2. delete a service (unless it is clear about the services required by software and hardware on your computer, it is not recommended to delete any system services, especially basic services)

3. Stop or start the service (the function is similar to net stop/start, but more services are faster and can be stopped)

The command format is as follows:

Modify the command line format of the Service Startup type to (note that START = is followed by a space)

SC config service name start = demand (set service to manual start)

SC config service name start = disabled (set service to disabled)

The command line format for stopping/starting a service is

SC stop/start service name

Note: The display name of the service is commonly used, and the above refers to the service name. You can double-click the corresponding service in the control panel> Management Tools> service to query it.

The following is an example of the specific setting method:

For example, if the remote registry service is set to manual

SC config RemoteRegistry start = demand

The disabled format is:

SC config RemoteRegistry start = disabled

When the service is stopped, the format is:

SC stop RemoteRegistry

First, check the service name you want to set and make a batch file according to the above format. After reinstalling the system, you only need to run the batch file.
The following are my settings, which are modeled on xpsp2 and can be used to add, delete, and modify the system. Note: No auto update, security center, or firewall has been added to XP SP2.

SC config Alerter start = demand

SC config TrkWks start = demand

SC config helpsvc start = demand

SC config PolicyAgent start = demand

SC config dmserver start = demand

SC config WmdmPmSN start = demand

SC config Spooler start = demand

SC config RemoteRegistry start = demand

SC config Ntmssvc start = demand

SC config seclogon start = demand

SC config schedule start = demand

SC config WebClient start = demand

SC config w32time start = demand

SC config WZCSVC start = demand

SC config ersvc start = demand

SC config themes start = demand

SC config FastUserSwitchingCompatibility start = disabled

SC config messenger start = disabled

SC config protectedstorage start = disabled

SC config ssdpsrv start = disabled

SC config termservice start = disabled

SC config ShellHWDetection start = disabled

If you need to immediately close the service, you can also add the following code after the above Code

SC stop w32time

SC stop ShellHWDetection

SC stop TrkWks

SC stop helpsvc

SC stop dmserver

SC stop yyagent

SC stop Spooler

SC stop RemoteRegistry

SC stop seclogon

SC stop schedule

SC stop WZCSVC

SC stop ersvc

SC stop themes

SC stop FastUserSwitchingCompatibility

SC stop protectedstorage

SC stop ssdpsrv

SC stop WebClient

Finally, save the modified Code as services. cmd. When you configure the service in the future, run the pre-saved batch file directly to get twice the result with half the effort.
Put the batch file together with the saved batch file, and then execute the batch file.

If you are familiar with the Registry, you may want to use the registry to set the Startup Type of the service. This is also a feasible method, but it has internal limitations. The reason is that the key values of the Service Startup Type in the Registry are long and scattered, which is inconvenient to organize and easy to error. Therefore, this method is suitable for unattended installation.

Use Case:

Start the automatic update service under the command line:

C: \> SC config wuauserv start = auto
[SC] changeserviceconfig success

C: \> SC start wuauserv

SERVICE_NAME: wuauserv
Type: 20 win32_0000_process
State: 2 start_pending
(Not_stoppable, not_pausable, ignores_shutdown)
Win32_exit_code: 0 (0x0)
Service_exit_code: 0 (0x0)
Checkpoint: 0x0
Wait_hint: 0x7d0
PID: 1156
Flags:

C: \>

CMD-SC command details: \> SC /?
Description:
SC is a command line program used to communicate with the Service Control Manager.
Usage:
SC <Server> [command] [service name] <option1> <option2>...

The format of option <Server> is \ servername"
You can type "SC [command]" for further help on the command.
Command:
Query ----------- query the service status,
Or enumerate the status of the service type.
Queryex --------- query the scaling status of a service,
Or enumerate the status of the service type.
Start ----------- start the service.
Pause ----------- send a pause control request to the service.
Interrogate ----- send an interrogate control request to the service.
Continue -------- send a continue control request to the service.
Stop ------------ send a stop request to the service.
Config ---------- (permanently) change the service configuration.
Description ----- change the service description.
Failure --------- operation performed when the service fails to be changed.
QC -------------- query service configuration information.
Qdescription ---- query the service description.
Qfailure -------- query the operation performed by the failed service.
Delete ---------- delete a service from the registry.
Create ---------- create a service (add it to the registry ).
Control --------- send control to service.
Sdshow ---------- display the service security descriptor.
Sdset ----------- set the service security descriptor.
Getdisplayname -- get the displayname of the service.
Getkeyname ------ get the servicekeyname of the service.
Enumdepend ------ enumerate service dependencies.

The following command does not query the service name:
SC <Server> <command> <option>
Boot ------------ (OK | bad) indicates whether to save the last startup
The last known STARTUP configuration
Lock ------------ lock the Service Database
Querylock ------- query the lockstatus of the scmanager Database
Example:
SC start myservice
SC config TrkWks start = disabled
SC config upnphost start = disabled
SC config ups start = disabled
SC config usprserv start = disabled
SC config VSS start = disabled
SC config w32time start = disabled
SC config WebClient start = disabled
SC config Winmgmt start = disabled
SC config wmconnectcds start = disabled
SC config WmdmPmSN start = disabled
SC config WMI start = disabled
SC config wmiApSrv start = disabled
SC config wmpnetworksvc start = disabled
SC config wscsvc start = disabled
SC config wuauserv start = disabled
SC config wudfsvc start = disabled
SC config WZCSVC start = disabled
SC config xmlprov start = disabled

: Xp2
Echo.
ECHO is backing up your service, so that you can recover it in time if any problem occurs.
Echo backup generates a bat (batch processing) file named after the current time.
When Echo is restored, double-click it. The backup is in progress. Please wait ......
@ Echo off
Rem get current date and time
For/F "tokens = 1, 2, 3, 4 delims = -/. "% J in ('date/t') do set filename = SRV _ % J _ % K _ % L _ % m

For/F "tokens = 1, 2 delims =:" % J in ('time/t') do set filename = % filename % _ % J _ % K. bat

Rem get all service name
SC Query type = Service State = All | findstr/R/C: "SERVICE_NAME:"> tmpsrv.txt
Echo save service start state in % filename %
Rem save service start state into batch file
Rem

Echo @ echo restore the service start state saved at % time % date %> "% filename %"
Echo @ pause> "% filename %"

For/F "tokens = 2 delims =:" % J in (tmpsrv.txt) do @ (SC QC % j | findstr start_type> tmpstype.txt & for/F "tokens = 4 delims =: _" % s in (tmpstype.txt) do @ echo SC config % J start = % S> "% filename % ")

Echo @ pause> "% filename %"
Del tmpsrv.txt
Del tmpstype.txt
Echo backup is complete. Start the optimization service program. Please wait ....
SC config Alerter start = disabled
SC config ALG start = disabled
SC config appmgmt start = disabled
SC config aspnet_state start = disabled
SC config audiosrv start = auto
SC config bits start = disabled
SC config browser start = disabled
SC config cisvc start = disabled
SC config clipsrv start = disabled
SC config comsysapp start = disabled
SC config cryptsvc start = demand
SC config dcomlaunch start = auto
SC config df5serv start = auto
SC config DHCP start = disabled
SC config dmadmin start = demand
SC config dmserver start = demand
SC config Dnscache start = disabled
SC config ersvc start = disabled
SC config EventLog start = auto
SC config EventSystem start = disabled
SC config FastUserSwitchingCompatibility start = disabled
SC config helpsvc start = disabled
SC config hidserv start = disabled
SC config httpfilter start = disabled
SC config idrivert start = demand
SC config imapiservice start = disabled
SC config LanmanServer start = disabled
SC config lanmanworkstation start = auto
SC config LmHosts start = disabled
SC config messenger start = disabled
SC config mnmsrvc start = disabled
SC config MSDTC start = disabled
SC config msiserver start = demand
SC config NETDDE start = disabled
SC config NetDDEdsdm start = disabled
SC config netlogon start = disabled

SC config netman start = demand
SC config NLA start = disabled
SC config NtLmSsp start = disabled
SC config Ntmssvc start = disabled
SC config nvsvc start = disabled
SC config ose start = disabled
SC config plugplay start = auto
SC config PolicyAgent start = disabled
SC config protectedstorage start = disabled
SC config RasAuto start = disabled
SC config RASMAN start = disabled
SC config RDSessMgr start = disabled
SC config RemoteAccess start = disabled
SC config RemoteRegistry start = disabled
SC config RpcLocator start = demand
SC config RPCSS start = auto
SC config RSVP start = disabled
SC config SamSs start = disabled
SC config SCardSvr start = disabled
SC config schedule start = disabled
SC config seclogon start = disabled
SC config sens start = disabled
SC config sharedaccess start = disabled
SC config ShellHWDetection start = disabled
SC config Spooler start = disabled
SC config srservice start = disabled
SC config ssdpsrv start = disabled
SC config stisvc start = disabled
SC config swprv start = disabled
SC config SysmonLog start = disabled
SC config tapisrv start = disabled
SC config termservice start = disabled
SC config themes start = disabled
SC config TlntSvr start = disabled
SC config TrkWks start = disabled
SC config telephony start = auto
SC config upnphost start = disabled
SC config ups start = disabled
SC config usprserv start = disabled
SC config VSS start = disabled
SC config w32time start = disabled
SC config WebClient start = disabled
SC config Winmgmt start = disabled
SC config wmconnectcds start = disabled
SC config WmdmPmSN start = disabled
SC config WMI start = disabled
SC config wmiApSrv start = disabled
SC config wmpnetworksvc start = disabled
SC config wscsvc start = disabled
SC config wuauserv start = disabled
SC config wudfsvc start = disabled
SC config WZCSVC start = disabled
SC config xmlprov start = disabled

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.