' 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.
'                 ADSI_USE_SECURE_AUTHENTICATION   0x00000001
'                 ADSI_USE_ENCRYPTION              0x00000010
'
Set objContainer = objMyNamespace.OpenDSObject _
   ("WinNT://UrMachineName","Administrator","AdminPwd",1)
' 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.
'
objNewUser.SetInfo
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.
   '
   objNewUser.SetPassword("TheNewPassword")
Else
   Response.Write("Error creating NT user.")
End If