using System.ServiceProcess; ServiceController myService = new ServiceController("MyService"); if (myService.Status == ServiceControllerStatus.Running) { myService.Pause(); }
using System.ServiceProcess; string serviceName = "MyService"; string machineName = "MyMachine"; ServiceController myService = new ServiceController(serviceName, machineName); if (myService.Status == ServiceControllerStatus.Running) { myService.Pause(); }In this example, we create a new ServiceController object for a service named "MyService" on a remote machine named "MyMachine." We then check if the service is currently running, and if it is, we call the Pause method to pause the service. Package library: System.ServiceProcess