Export (0) Print
Expand All

ServiceController::GetServices Method

Retrieves all the services on the local computer, except for the device driver services.

Namespace:  System.ServiceProcess
Assembly:  System.ServiceProcess (in System.ServiceProcess.dll)

static array<ServiceController^>^ GetServices()

Return Value

Type: array<System.ServiceProcess::ServiceController>
An array of type ServiceController in which each element is associated with a service on the local computer.


An error occurred when accessing a system API.

GetServices returns only the non-device driver services and the services that are not drivers from the local computer. To retrieve device driver services, call the GetDevices method. Together, the two methods provide access to all the services on a computer.

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft