2009-12-22 133 views

回答

3
// ADD "using System.ServiceProcess;" after you add the 
// Reference to the System.ServiceProcess in the solution Explorer 
using System.ServiceProcess; 

ServiceController myService = new ServiceController();  
myService.ServiceName = "ImapiService"; 

string svcStatus = myService.Status.ToString(); 

if (svcStatus == "Running") 
{ 
    myService.Stop(); 
} 
else if(svcStatus == "Stopped") 
{ 
    myService.Start(); 
} 
else 
{ 
    myService.Stop(); 
} 
1

「run」是什麼意思?如果您想要控制(啓動,停止和以其他方式操作)安裝在本地(或遠程)機器上的服務,則需要使用ServiceController