The following Visual Basic code example creates a user on a member server or Windows 2000 Professional.
' Example: Creating a user on a member server or workstation
Dim cont As IADsContainer
Dim oUser As IADsUser
Dim v As Variant
On Error GoTo Cleanup
''''''''''''''''''''
' Parse the arguments
''''''''''''''''''''
sComputer =
InputBox("This script creates a user on a member " _
& "server or workstation." _
& vbCrLf & vbCrLf _
& "Specify the computer name:")
If sComputer = "" Then
Exit Sub
End If
sUser = InputBox("Specify the user name:")
If sUser = "" Then
Exit Sub
End If
''''''''''''''''''''
' Bind to the computer.
''''''''''''''''''''
Set cont = GetObject("WinNT://" & sComputer & ",computer")
''''''''''''''''''''
' Create the user.
''''''''''''''''''''
Set oUser = cont.Create("user", sUser)
'''''''''''''''''''''''''''
' Write the user to the computer's security database.
'''''''''''''''''''''''''''
oUser.SetInfo
strText = "The user " & sUser & " was successfully added."
strText = strText & vbCrLf _
& "The user has the following properties:"
'''''''''''''''''''''
' Read the user that was just created
' and display its name and its properties.
'''''''''''''''''''''
oUser.GetInfo
strText = strText & "Number of properties: " & Count
For cprop = 1 To Count
Set v = oUser.Next()
If IsNull(v) Then
Exit For
End If
strText = strText & vbCrLf & cprop & ") " & v.Name _
& " (" & v.ADsType & ") "
Next
MsgBox strText, vbInformation, "Create user on " & sComputer
Cleanup:
If (Err.Number<>0) Then
MsgBox ("An error has occurred. " & Err.Number)
Set cont = Nothing
Set oUser = Nothing
Set v = Nothing
Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.
