得到windows服務的列表並查找服務的名稱。


這個例子展示了如何得到在本機安裝的Windows服務。

 

得到已經安裝的windows services

為了得到所有服務(不是設備驅動),可以使用 ServiceContro­ller.GetServices (取得驅動服務是用 ServiceController.GetDevices).

 

[C#]

 

1
ServiceController[] services = ServiceController.GetServices();
檢測服務是否安裝
下面的代碼檢測服務有沒有在本機安裝。得到windows服務的列表並查找服務的名稱。
 
[C#]
1
2
3
4
5
6
7
8
9
10
11
12
13
public static bool IsServiceInstalled( string serviceName)
{
   // get list of Windows services
   ServiceController[] services = ServiceController.GetServices();
 
   // try to find service name
   foreach (ServiceController service in services)
   {
     if (service.ServiceName == serviceName)
       return true ;
   }
   return false ;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM