ServiceController.GetServices Método

Definição

Recupera os serviços que não são de driver de dispositivo em um computador, bem como aqueles que não são drivers.Retrieves the non-device driver services on a computer, and those that are not drivers.

Sobrecargas

GetServices(String)

Recupera todos os serviços no computador especificado, exceto os serviços de driver de dispositivo.Retrieves all the services on the specified computer, except for the device driver services.

GetServices()

Recupera todos os serviços no computador local, exceto os serviços de driver de dispositivo.Retrieves all the services on the local computer, except for the device driver services.

GetServices(String)

Recupera todos os serviços no computador especificado, exceto os serviços de driver de dispositivo.Retrieves all the services on the specified computer, except for the device driver services.

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()

Parâmetros

machineName
String

O computador do qual os serviços devem ser recuperados.The computer from which to retrieve the services.

Retornos

ServiceController[]

Uma matriz do tipo ServiceController na qual cada elemento é associado um serviço no computador especificado.An array of type ServiceController in which each element is associated with a service on the specified computer.

Exceções

Ocorreu um erro ao acessar uma API do sistema.An error occurred when accessing a system API.

O parâmetro machineName tem uma sintaxe inválida.The machineName parameter has invalid syntax.

Comentários

GetServices retorna somente os serviços de driver que não são de dispositivo e os serviços que não são drivers do computador especificado.GetServices returns only the non-device driver services and the services that are not drivers from the specified computer. Para recuperar os serviços de driver de dispositivo, chame o GetDevices método.To retrieve device driver services, call the GetDevices method. Juntos, os dois métodos fornecem acesso a todos os serviços em um computador.Together, the two methods provide access to all the services on a computer.

Confira também

Aplica-se a

GetServices()

Recupera todos os serviços no computador local, exceto os serviços de driver de dispositivo.Retrieves all the services on the local computer, except for the device driver services.

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()

Retornos

ServiceController[]

Uma matriz do tipo ServiceController na qual cada elemento é associado a um serviço no computador local.An array of type ServiceController in which each element is associated with a service on the local computer.

Exceções

Ocorreu um erro ao acessar uma API do sistema.An error occurred when accessing a system API.

Exemplos

O exemplo a seguir usa a ServiceController classe para exibir os serviços que estão em execução no computador local.The following example uses the ServiceController class to display the services that are running on the local computer.

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

Comentários

GetServices retorna somente os serviços de driver que não são de dispositivo e os serviços que não são drivers do computador local.GetServices returns only the non-device driver services and the services that are not drivers from the local computer. Para recuperar os serviços de driver de dispositivo, chame o GetDevices método.To retrieve device driver services, call the GetDevices method. Juntos, os dois métodos fornecem acesso a todos os serviços em um computador.Together, the two methods provide access to all the services on a computer.

Confira também

Aplica-se a