Managing Services Using ADSI and Windows Script Host (234001)



The information in this article applies to:

  • Microsoft Windows NT Server 4.0 Terminal Server Edition
  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Professional
  • Microsoft Windows NT Server 4.0
  • Microsoft Windows NT Workstation 4.0
  • Microsoft Active Directory Service Interfaces 2.5

This article was previously published under Q234001

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.
PropertyDescription
DependenciesThe list of services you need to start before you can start this service.
DisplayNameThe friendly name that is displayed for this service.
ErrorControlThe severity of the alert if the service does not start.
HostComputerThe ADsPath string of the host of this service.
LoadOrderGroupName of the load order group of which this service is a member.
PathPath and filename of the executable file for this service.
ServiceAccountNameName of the account that this service uses for authentication.
ServiceAccountPathThe ADsPath string for the user account this service is using.
ServiceTypeThe description of the service type on the host computer.
StartTypeOne of five possible types that determines when this service starts.
StartupParametersParameters passed to the service executable file.
VersionVersion information of the service.
The IADsServiceOperations service settings are listed in the following table.
PropertyDescription
StatusThe current operational state of the service.
StartStarts the service.
StopStops the service.
PausePauses the service.
ContinueResumes the paused service.
SetPasswordSets 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: For information about Windows Script Host, VBScript, and JScript, please visit the following Microsoft Web site:

Modification Type:MajorLast Reviewed:10/9/2006
Keywords:kbenv kbhowto KB234001