C # Stop the Management Service

Source: Internet
Author: User

Due to machine performance problems, many services are disabled and need to be enabled again when needed. In this way, it is troublesome to open the service management or cmd command every time, and the tool is displayed on the desktop by yourself;

Service Management and add references

 
System. serviceprocess;

Statement

 
Servicecontroller mycontroller = new system. serviceprocess. servicecontroller (Service name );

Start the service

 
Mycontroller. Start ();

Suspend Service

 
Mycontroller. Pause ();

Continue Service

 
Mycontroller. Continue ();

Stop Service

 
Mycontroller. Stop ();

Refresh Service

 
Mycontroller. Refresh ();

 

Service Status:

Servicecontrollerstatus enumeration indicates the current status of the service
Member

Member name Description
Continuepending The service is about to continue. This corresponds to Win32Service_continue_pendingConstant, which is defined as 0x00000005.
Paused The service has been suspended. This corresponds to Win32Service_pausedConstant, which is defined as 0x00000007.
Pausepending The service is about to be suspended. This corresponds to Win32Service_pause_pendingConstant, which is defined as 0x00000006.
Running The service is running. This corresponds to Win32Service_runningConstant, which is defined as 0x00000004.
Startpending The service is starting. This corresponds to Win32Service_start_pendingConstant, which is defined as 0x00000002.
Stopped The service is not running. This corresponds to Win32Service_stoppedConstant, which is defined as 0x00000001.
Stoppending The service is being stopped. This corresponds to Win32Service_stop_pendingConstant, which is defined as 0x00000003.

 

Related Article

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.