I am trying to create NT users and exchange 5.5 mailboxes with a small app. The code below is to create a NT account. The line in red is causing this error:
"Run-Time error '-2147022651 (800708c5)"
"Automation Error"
Anyone know why? If I remove the line the rest of the code works but it doesn't set a password then.
Public Function Create_NT_Account(strDomain As String, _
strAdmin As String, _
strPassword As String, _
UserName As String, _
FullName As String, _
NTServer As String _
) As Boolean
Dim oNS As IADsOpenDSObject
Dim User As IADsUser
Dim Domain As IADsDomain
On Error GoTo Create_NT_Account_Error
Create_NT_Account = False
If (strPassword = ""
Then
strPassword = ""
End If
Set oNS = GetObject("WinNT:"
Set Domain = oNS.OpenDSObject("WinNT://" & strDomain, strDomain & "\" & strAdmin, strPassword, 0)
Set User = Domain.Create("User", UserName)
With User
.Description = "User created by ADSI"
.FullName = FullName
.HomeDirectory = "\\" & NTServer & "\" & UserName
.LoginScript = LOGON_CMD
.SetInfo
' First password = username
.SetPassword UserName
End With
Debug.Print "Successfully created NT Account for user " & UserName
Create_NT_Account = True
Exit Function
Create_NT_Account_Error:
Debug.Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred creating NT account for user " & UserName
End Function
"Run-Time error '-2147022651 (800708c5)"
"Automation Error"
Anyone know why? If I remove the line the rest of the code works but it doesn't set a password then.
Public Function Create_NT_Account(strDomain As String, _
strAdmin As String, _
strPassword As String, _
UserName As String, _
FullName As String, _
NTServer As String _
) As Boolean
Dim oNS As IADsOpenDSObject
Dim User As IADsUser
Dim Domain As IADsDomain
On Error GoTo Create_NT_Account_Error
Create_NT_Account = False
If (strPassword = ""
strPassword = ""
End If
Set oNS = GetObject("WinNT:"
Set Domain = oNS.OpenDSObject("WinNT://" & strDomain, strDomain & "\" & strAdmin, strPassword, 0)
Set User = Domain.Create("User", UserName)
With User
.Description = "User created by ADSI"
.FullName = FullName
.HomeDirectory = "\\" & NTServer & "\" & UserName
.LoginScript = LOGON_CMD
.SetInfo
' First password = username
.SetPassword UserName
End With
Debug.Print "Successfully created NT Account for user " & UserName
Create_NT_Account = True
Exit Function
Create_NT_Account_Error:
Debug.Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred creating NT account for user " & UserName
End Function