Managing Services Using ADSI and Windows Script Host

ID: Q234001


The information in this article applies to:
  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Professional
  • Microsoft Windows NT Server version 4.0
  • Microsoft Windows NT Server version 4.0, Terminal Server Edition
  • Microsoft Windows NT Workstation version 4.0
  • Microsoft Active Directory Service Interfaces, version 2.5


SUMMARY

This article describes how to manage services using Active Directory Services Interface (ADSI) and Windows Script Host.


MORE INFORMATION

You can use ADSI and Windows Script Host to write scripts that allow you to manage local and remote services. This article describes the different methods and properties ADSI provides for services, as well as script examples.

The ADSI Service Object supports two COM interfaces, IADsService and IADsServiceOperations.

The properties of the IADsService interface are list in the following table.

Property Description
Dependencies The list of services you need to start before you can start this service.
DisplayName The friendly name that is displayed for this service.
ErrorControl The severity of the alert if the service does not start.
HostComputer The ADsPath string of the host of this service.
LoadOrderGroup Name of the load order group of which this service is a member.
Path Path and filename of the executable file for this service.
ServiceAccountName Name of the account that this service uses for authentication.
ServiceAccountPath The ADsPath string for the user account this service is using.
ServiceType The description of the service type on the host computer.
StartType One of five possible types that determines when this service starts.
StartupParameters Parameters passed to the service executable file.
Version Version information of the service.
The IADsServiceOperations service settings are listed in the following table.
Property Description
Status The current operational state of the service.
Start Starts the service.
Stop Stops the service.
Pause Pauses the service.
Continue Resumes the paused service.
SetPassword Sets the password for the Service Account.
The following example of VBScript code lists the services on a computer with some common properties:

Set ComputerObj = GetObject("WinNT://MYCOMPUTER")
ComputerObj.Filter = Array("Service")
For Each Service in ComputerObj
    WScript.Echo "Service display name = " & Service.DisplayName
    WScript.Echo "Service account name = " & Service.ServiceAccountName
    WScript.Echo "Service executable   = " & Service.Path
    WScript.Echo "Current status       = " & Service.Status
Next 


The following Visual Basic script starts the Computer Browser service on MYCOMPUTER:


Set Service = GetObject("WinNT://MYCOMPUTER/BROWSER,Service")
Service.Start 


The following Visual Basic script sets the user account and password for the Directory Replicator service on MYCOMPUTER:


Set Service = GetObject("WinNT://MYCOMPUTER/REPLICATOR,Service")
Service.ServiceAccountName = "ARCADIABAY\JSmith"
Service.SetPassword "TopSecret"
Service.SetInfo 


For information about ADSI, please visit the following Microsoft Web site:
http://www.microsoft.com/windows/server/Technical/directory/adsilinks.asp
For information about Windows Script Host, VBScript, and JScript, please visit the following Microsoft Web site:
http://msdn.microsoft.com/scripting/

Additional query words:

Keywords : kbenv kbtool kbADSI kbNTOS400 kbWinOS2000 kbDSupport
Version : WINDOWS:2000; winnt:2.5,4.0
Platform : WINDOWS winnt
Issue type : kbhowto


Last Reviewed: December 30, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.