ServiceController.GetServices ServiceController.GetServices ServiceController.GetServices ServiceController.GetServices Method

Definizione

Recupera tutti i servizi del driver non di dispositivo su un computer e quelli che non sono driver.Retrieves the non-device driver services on a computer, and those that are not drivers.

Overload

GetServices(String) GetServices(String) GetServices(String) GetServices(String)

Recupera tutti i servizi sul computer specificato, fatta eccezione per i servizi del driver di dispositivo.Retrieves all the services on the specified computer, except for the device driver services.

GetServices() GetServices() GetServices() GetServices()

Recupera tutti i servizi sul computer locale, fatta eccezione per i servizi del driver di dispositivo.Retrieves all the services on the local computer, except for the device driver services.

GetServices(String) GetServices(String) GetServices(String) GetServices(String)

Recupera tutti i servizi sul computer specificato, fatta eccezione per i servizi del driver di 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()

Parametri

machineName
String String String String

Il computer da cui recuperare i servizi.The computer from which to retrieve the services.

Restituisce

Matrice di tipo ServiceController, nella quale ciascun elemento è associato a un servizio sul computer specificato.An array of type ServiceController in which each element is associated with a service on the specified computer.

Eccezioni

Si è verificato un errore durante l'accesso a un'API di sistema.An error occurred when accessing a system API.

La sintassi del parametro machineName non è valida.The machineName parameter has invalid syntax.

Commenti

GetServices Restituisce solo i servizi del driver non di dispositivo e i servizi che non sono driver dal computer specificato.GetServices returns only the non-device driver services and the services that are not drivers from the specified computer. Per recuperare i servizi del driver di dispositivo, chiamare il GetDevices (metodo).To retrieve device driver services, call the GetDevices method. Insieme, i due metodi forniscono l'accesso a tutti i servizi in un computer.Together, the two methods provide access to all the services on a computer.

Vedi anche

GetServices() GetServices() GetServices() GetServices()

Recupera tutti i servizi sul computer locale, fatta eccezione per i servizi del driver di 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()

Restituisce

Matrice di tipo ServiceController, nella quale ciascun elemento è associato a un servizio sul computer locale.An array of type ServiceController in which each element is associated with a service on the local computer.

Eccezioni

Si è verificato un errore durante l'accesso a un'API di sistema.An error occurred when accessing a system API.

Esempi

L'esempio seguente usa il ServiceController classe per visualizzare i servizi in esecuzione nel computer locale.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 (LocalSytem, 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 (LocalSytem, 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 (LocalSytem, 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

Commenti

GetServices Restituisce solo i servizi del driver non di dispositivo e i servizi che non sono driver dal computer locale.GetServices returns only the non-device driver services and the services that are not drivers from the local computer. Per recuperare i servizi del driver di dispositivo, chiamare il GetDevices (metodo).To retrieve device driver services, call the GetDevices method. Insieme, i due metodi forniscono l'accesso a tutti i servizi in un computer.Together, the two methods provide access to all the services on a computer.

Vedi anche

Si applica a