Set, start, and stop services using batch processing

Source: Internet
Author: User

When database services (such as Oracle and sqlserver) or some web services (such as IIS and tomcat) are installed on our computer, many services are added. These services often occupy a large amount of system resources. It is a great waste of system resources if you are always in the starting state when you do not need it at ordinary times. Therefore, we can stop all unnecessary services through the "service" in "Management Tools. However, it is difficult to manually start or stop each time you use or do not use it. So I thought of using batch operations.
The following describes two methods to set, start, and stop services using batch processing.
Starting from Windows XP, a file of SC .exe (Service control.exe and net.exe (c: \ windows \ system32) is added to its built-in dos tool, allowing you to perform operations on the Service Startup Type and Service Startup or shutdown, with the advantages of DOS batch processing, you can simplify the operations mentioned above.
Method 1: 
Common SC .exe functions:
1. Change the service startup status.
2. Delete the Service (otherwise, it is not recommended to delete any system service, especially the basic service with caution)
3. Stop or start the service (the function is similar to net stop/start, but more services are faster and can be stopped)
Specific command format:
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 service name can be queried by double-clicking the corresponding service display name in the control panel> Administrative Tools> service.
Example:
Set Remote Registry Service to manual format
SC config RemoteRegistry start = demand
Set the disabled format
SC config RemoteRegistry start = disabled
When the service is stopped, the format is
SC stop RemoteRegistry
Method 2: 
Use the net.exe function to start or stop services
The command line format for starting/stopping a service is
Net start/stop service name
Example:
Take starting and stopping the Oracle service as an example: Because the Oracle service occupies a lot of system resources and does not usually use the Oracle database. So I set it to manual start, and each time I use Oracle, I use batch processing to start a bunch of services.
-- Start Oracle services
@ Echo off
Net start oraclemtsrecoveryservice
Net start oracleorahome92agent
Net start oracleorahome92tnslistener
Net start oracleservice Database Name
-- Stop Oracle services
@ Echo off
Net stop oracleservice Database Name
Net stop oracleorahome92tnslistener
Net stop oracleorahome92agent
Net stop oraclemtsrecoveryservice

Start method: 
Method 1. After saving the file, you can directly double-click the file to start or close the service.
Method 2. Set Environment Variables
In the system variables in the environment variables, add the path of the batch file after the path. Do not forget to use a semicolon; separate it from the previous environment variables, then, enter the executable file directly in the running of the Start Menu.
Environment variables are used to tell the system where information is entered during running.

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.