回答

2

有關如何檢查服務在啓動條件下運行,見this線的詳細信息,

最可靠的自定義操作將是一個C++ DLL調用兩個UI的 LaunchConditions行動之前插入執行序列。

有一個在這裏的一個例子:

http://support.microsoft.com/default.aspx?scid=kb;en-us;253683

您的自定義操作代碼可以檢查正在運行的服務,併爲LaunchConditions設置屬性 。

您可以使用ServiceController.GetServices方法列出在本地計算機上運行的服務。

ServiceController[] scServices; 
scServices = ServiceController.GetServices(); 

// Display the list of services currently running on this computer. 

Console.WriteLine("Services running on the local computer:"); 
foreach (ServiceController scTemp in scServices) 
{ 
    if (scTemp.Status == ServiceControllerStatus.Running) 
    { 
     // Write the service name and the display name 
     // for each running service. 
     Console.WriteLine(); 
     Console.WriteLine(" Service :  {0}", scTemp.ServiceName); 
     Console.WriteLine(" Display name: {0}", scTemp.DisplayName); 
    } 
} 
2

您可以連接到服務如下:

ServiceController sc = new ServiceController("ServiceName"); 

如果該服務是通過檢查「狀態」屬性運行,則可以檢查。 Status返回ServiceControllerStatus類型的值(枚舉)。

相關問題