ServiceController.GetServices Метод

Определение

Извлекает службы драйверов, отличные от устройств на компьютере, и те, которые не являются драйверами.

Перегрузки

Имя Описание
GetServices(String)

Извлекает все службы на указанном компьютере, кроме служб драйверов устройств.

GetServices()

Извлекает все службы на локальном компьютере, за исключением служб драйверов устройств.

GetServices(String)

Исходный код:
ServiceController.cs
Исходный код:
ServiceController.cs
Исходный код:
ServiceController.cs
Исходный код:
ServiceController.cs

Извлекает все службы на указанном компьютере, кроме служб драйверов устройств.

public:
 static cli::array <System::ServiceProcess::ServiceController ^> ^ GetServices(System::String ^ machineName);
public static System.ServiceProcess.ServiceController[] GetServices(string machineName);
static member GetServices : string -> System.ServiceProcess.ServiceController[]
Public Shared Function GetServices (machineName As String) As ServiceController()

Параметры

machineName
String

Компьютер, из которого необходимо получить службы.

Возвращаемое значение

Массив типа ServiceController , в котором каждый элемент связан со службой на указанном компьютере.

Исключения

Ошибка при доступе к системным API.

Параметр имеет недопустимый machineName синтаксис.

Комментарии

GetServices возвращает только службы драйверов, отличные от устройств, и службы, которые не являются драйверами с указанного компьютера. Чтобы получить службы драйверов устройств, вызовите GetDevices метод. Вместе два метода обеспечивают доступ ко всем службам на компьютере.

См. также раздел

Применяется к

GetServices()

Исходный код:
ServiceController.cs
Исходный код:
ServiceController.cs
Исходный код:
ServiceController.cs
Исходный код:
ServiceController.cs

Извлекает все службы на локальном компьютере, за исключением служб драйверов устройств.

public:
 static cli::array <System::ServiceProcess::ServiceController ^> ^ GetServices();
public static System.ServiceProcess.ServiceController[] GetServices();
static member GetServices : unit -> System.ServiceProcess.ServiceController[]
Public Shared Function GetServices () As ServiceController()

Возвращаемое значение

Массив типа ServiceController , в котором каждый элемент связан со службой на локальном компьютере.

Исключения

Ошибка при доступе к системным API.

Примеры

В следующем примере класс используется ServiceController для отображения служб, работающих на локальном компьютере.

array<ServiceController^>^scServices = ServiceController::GetServices();

// Display the list of services currently running on this computer.
Console::WriteLine(  "Services running on the local computer:" );
for each (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 );

      // Query WMI for additional information about this service.
      // Display the start name (LocalSystem, etc) and the service
      // description.
      ManagementObject^ wmiService;
      String^ objPath;
      objPath = String::Format( "Win32_Service.Name='{0}'", scTemp->ServiceName );
      wmiService = gcnew ManagementObject( objPath );
      if ( wmiService )
      {
         wmiService->Get();
         Object^ objStartName = wmiService["StartName"];
         Object^ objDescription = wmiService["Description"];
         if ( objStartName )
         {
            Console::WriteLine(  "    Start name:      {0}", objStartName->ToString() );
         }
         if ( objDescription )
         {
            Console::WriteLine(  "    Description:     {0}", objDescription->ToString() );
         }
      }
   }
}
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);

      // Query WMI for additional information about this service.
      // Display the start name (LocalSystem, etc) and the service
      // description.
      ManagementObject wmiService;
      wmiService = new ManagementObject("Win32_Service.Name='" + scTemp.ServiceName + "'");
      wmiService.Get();
      Console.WriteLine("    Start name:      {0}", wmiService["StartName"]);
      Console.WriteLine("    Description:     {0}", wmiService["Description"]);
   }
}

   Dim scServices() As ServiceController
   scServices = ServiceController.GetServices()
 
   ' Display the list of services currently running on this computer.
   Console.WriteLine("Services running on the local computer:")

   Dim scTemp As ServiceController
   For Each scTemp In  scServices

      If scTemp.Status = ServiceControllerStatus.Running Then
         ' 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)
         
         ' Query WMI for additional information about this service.
         ' Display the start name (LocalSystem, etc) and the service
         ' description.
         Dim wmiService As ManagementObject
         wmiService = New ManagementObject("Win32_Service.Name='" + scTemp.ServiceName + "'")
         wmiService.Get()
         Console.WriteLine("    Start name:      {0}", wmiService("StartName"))
         Console.WriteLine("    Description:     {0}", wmiService("Description"))
      End If

   Next scTemp

Комментарии

GetServices возвращает только службы драйверов, отличные от устройств, и службы, которые не являются драйверами на локальном компьютере. Чтобы получить службы драйверов устройств, вызовите GetDevices метод. Вместе два метода обеспечивают доступ ко всем службам на компьютере.

См. также раздел

Применяется к