ServiceController.GetServices Methode

Definitie

Haalt de services voor niet-apparaatstuurprogramma's op een computer op en de services die geen stuurprogramma's zijn.

Overloads

Name Description
GetServices(String)

Hiermee worden alle services op de opgegeven computer opgehaald, met uitzondering van de apparaatstuurprogrammaservices.

GetServices()

Hiermee worden alle services op de lokale computer opgehaald, met uitzondering van de apparaatstuurprogrammaservices.

GetServices(String)

Hiermee worden alle services op de opgegeven computer opgehaald, met uitzondering van de apparaatstuurprogrammaservices.

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

Parameters

machineName
String

De computer waaruit de services moeten worden opgehaald.

Retouren

Een matrix van het type ServiceController waarin elk element is gekoppeld aan een service op de opgegeven computer.

Uitzonderingen

Er is een fout opgetreden bij het openen van een systeem-API.

De machineName parameter heeft een ongeldige syntaxis.

Opmerkingen

GetServices retourneert alleen de niet-apparaatstuurprogrammaservices en de services die geen stuurprogramma's van de opgegeven computer zijn. Als u services voor apparaatstuurprogramma's wilt ophalen, roept u de GetDevices methode aan. De twee methoden bieden samen toegang tot alle services op een computer.

Zie ook

Van toepassing op

GetServices()

Hiermee worden alle services op de lokale computer opgehaald, met uitzondering van de apparaatstuurprogrammaservices.

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

Retouren

Een matrix van het type ServiceController waarin elk element is gekoppeld aan een service op de lokale computer.

Uitzonderingen

Er is een fout opgetreden bij het openen van een systeem-API.

Voorbeelden

In het volgende voorbeeld wordt de ServiceController klasse gebruikt om de services weer te geven die op de lokale computer worden uitgevoerd.

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

Opmerkingen

GetServices retourneert alleen de niet-apparaatstuurprogrammaservices en de services die geen stuurprogramma's van de lokale computer zijn. Als u services voor apparaatstuurprogramma's wilt ophalen, roept u de GetDevices methode aan. De twee methoden bieden samen toegang tot alle services op een computer.

Zie ook

Van toepassing op