ServiceController.GetServices Método

Definición

Recupera los servicios de controladores que no son dispositivos en un equipo y los que no son controladores.Retrieves the non-device driver services on a computer, and those that are not drivers.

Sobrecargas

GetServices(String)

Recupera todos los servicios del equipo especificado, excepto los servicios de controlador de dispositivos.Retrieves all the services on the specified computer, except for the device driver services.

GetServices()

Recupera todos los servicios del equipo local, excepto los servicios de controlador de dispositivos.Retrieves all the services on the local computer, except for the device driver services.

GetServices(String)

Recupera todos los servicios del equipo especificado, excepto los servicios de controlador de dispositivos.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

Equipo desde el que se recuperan los servicios.The computer from which to retrieve the services.

Devoluciones

ServiceController[]

Matriz de tipo ServiceController en la que cada elemento está asociado a un servicio en el equipo especificado.An array of type ServiceController in which each element is associated with a service on the specified computer.

Excepciones

Error de acceso a la API del sistema.An error occurred when accessing a system API.

El parámetro machineName tiene una sintaxis no válida.The machineName parameter has invalid syntax.

Comentarios

GetServices solo devuelve los servicios de controladores que no son de dispositivo y los servicios que no son controladores del equipo especificado.GetServices returns only the non-device driver services and the services that are not drivers from the specified computer. Para recuperar los servicios de controlador de dispositivo, llame al GetDevices método.To retrieve device driver services, call the GetDevices method. Juntos, los dos métodos proporcionan acceso a todos los servicios de un equipo.Together, the two methods provide access to all the services on a computer.

Consulte también

Se aplica a

GetServices()

Recupera todos los servicios del equipo local, excepto los servicios de controlador de dispositivos.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()

Devoluciones

ServiceController[]

Matriz de tipo ServiceController en la que cada elemento está asociado a un servicio en el equipo local.An array of type ServiceController in which each element is associated with a service on the local computer.

Excepciones

Error de acceso a la API del sistema.An error occurred when accessing a system API.

Ejemplos

En el ejemplo siguiente se usa la ServiceController clase para mostrar los servicios que se ejecutan en el equipo 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

Comentarios

GetServices solo devuelve los servicios de controladores que no son de dispositivo y los servicios que no son controladores del equipo local.GetServices returns only the non-device driver services and the services that are not drivers from the local computer. Para recuperar los servicios de controlador de dispositivo, llame al GetDevices método.To retrieve device driver services, call the GetDevices method. Juntos, los dos métodos proporcionan acceso a todos los servicios de un equipo.Together, the two methods provide access to all the services on a computer.

Consulte también

Se aplica a