This documentation is archived and is not being maintained.

ServiceController.ServicesDependedOn Property

The set of services that this service depends on.

[Visual Basic]
Public ReadOnly Property ServicesDependedOn As ServiceController ()
[C#]
public ServiceController[] ServicesDependedOn {get;}
[C++]
public: __property ServiceController* get_ServicesDependedOn();
[JScript]
public function get ServicesDependedOn() : ServiceController[];

Property Value

An array of ServiceController instances, each of which is associated with a service that must be running for this service to run.

Exceptions

Exception Type Condition
Win32Exception An error occurred when accessing a system API.

Remarks

If any service in the ServicesDependedOn array is not running, you will not be able to start this service.

Example

[Visual Basic, C#, C++] The following example uses the ServiceController class to display the set of services that the Messenger service is dependent on.

[Visual Basic] 

         Dim sc As New ServiceController("Messenger")
         Dim scServices As ServiceController() = sc.ServicesDependedOn
         
         ' Display the services that the Messenger service is dependent on.
         If scServices.Length = 0 Then
            Console.WriteLine("{0} service is not dependent on any other services.", sc.ServiceName)
         Else
            Console.WriteLine("{0} service is dependent on the following:", sc.ServiceName)
            
            Dim scTemp As ServiceController
            For Each scTemp In  scServices
               Console.WriteLine(" {0}", scTemp.DisplayName)
            Next scTemp
         End If


[C#] 
ServiceController sc = new ServiceController("Messenger");
ServiceController[] scServices= sc.ServicesDependedOn;

// Display the services that the Messenger service is dependent on.
if (scServices.Length == 0)
{
   Console.WriteLine("{0} service is not dependent on any other services.", 
                      sc.ServiceName);
}
else 
{
   Console.WriteLine("{0} service is dependent on the following:",
                      sc.ServiceName);

   foreach (ServiceController scTemp in scServices)
   {
      Console.WriteLine(" {0}", scTemp.DisplayName);
   }
}

[C++] 
ServiceController *sc = new ServiceController("Messenger");
ServiceController * scServices[] = 0;

if (sc)
{
   scServices = sc->ServicesDependedOn;
}

if (sc && scServices)
{
   // Display the services that the Messenger service is dependent on.
   if (scServices->Length == 0)
   {
      Console::WriteLine("{0} service is not dependent on any other services.", 
                         sc->ServiceName);
   }
   else 
   {
      Console::WriteLine("{0} service is dependent on the following:",
                        sc->ServiceName);

      for (int i=0; i<scServices->Length; i++)
      {
         ServiceController *scTemp = scServices[i];
         Console::WriteLine(" {0}", scTemp->DisplayName);
      }
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

ServiceController Class | ServiceController Members | System.ServiceProcess Namespace

Show: