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