RE: change NT PASSWORD using ASP

Cook, John ( (no email) )
Mon, 12 Jan 1998 07:17:57 -0600

The following VB Script ASP code was adapted from Microsoft's ADSI

' An Active Directory object is a COM object that represents a
' part of the natural hierarchical structure of directory trees
' or directory services supplied over a network.
' All object creation and management occurs within a parent Active
' Directory Container Object.

' IMPORTANT: If you want to create a new NT account on a remote
' machine, you must have rights to log on to that machine.

Option Explicit
On Error Resume Next
Dim objMyNamespace, objContainer, objNewUser

' GetObject - Binds to ADsPath name.
' [in] ADsPath in URL format
Set objMyNamespace = GetObject("WinNT:")

' OpenDSObject - Binds to an ADSI object using the given credential.
' 1. [in] ADsPath of the ADSI object.
' 2. [in] The user name to be used for securing permission
' from the namespace server.
' 3. [in] The password to be used for securing permission
' from the namespace server.
' 4. [in] Flags that define the binding options.
Set objContainer = objMyNamespace.OpenDSObject _

' Make the request to create the specified NT username.
' Create - Sets up request to create Active Directory object of the
' specified schema class and name in this objContainer object.
' 1. [in] Name of the schema class object to create,
' as it is found through the IADs::get_Schema method.
' 2. [in] Name of the object as it is known in the underlying
' directory and identical to the one retrieved through
' the IADs::get_Name method.
Set objNewUser = objContainer.Create("user","newNTusername")

' Set the properties of the new NT user to be created.
objNewUser.FullName = "Ura User"
objNewUser.Description = "NT User created by ADSI"

' Actually create the NT user using the preceeding request definition.
' SetInfo - Saves the current values for the properties for
' this Active Directory object from the property cache
' to the underlying directory store. This is analogous
' to flushing a buffer out to disk.
If Err.Number = 0 Then

' Set the password.
' SetPassword - Sets the password for the account used by the
' service manager when creating the security context
' for this service.
' [in] The password to be stored as the new password.
Response.Write("Error creating NT user.")
End If