0

I am running into a strange error in VBScript:

[...]
            objUser.sAMAccountName = strNTName
            On Error Resume Next
            objUser.SetInfo
            If (Err.Number <> 0) Then
                On Error GoTo 0
                Wscript.Echo "Unable to create user with NT name: " & strNTName & " - Error-Code: " & Err.Number & " (sAMAccountName)"
            Else
[...]

Well I get a message box: Unable to create user with NT name: testuser - Error-Code: 0 (sAMAccountName)

How can that happen? What am I doing wrong? Is 0 <> 0?!? Also tried "0" to be sure...


Update: Now - thanks to @JosefZ I sorted out the Error code -2147016651 But that does not help me eigther... New Code:

[...]
    Set objUser = objContainer.Create("user", "cn=" & strCN)
    If (Err.Number <> 0) Then
        On Error GoTo 0
        Wscript.Echo "Unable to create user with cn: " & strCN
    Else
        On Error GoTo 0
        ' Assign mandatory attributes and save user object.
        If (strNTName = "") Then
            strNTName = strCN
        End If
            objUser.sAMAccountName = strNTName
            On Error Resume Next
            objUser.SetInfo
            If (Err.Number <> 0) Then
                Wscript.Echo "Unable to create user with NT name: " & strNTName & " - Error-Code: " & Err.Number & " (sAMAccountName)"
                On Error GoTo 0
            Else
[...]

strNTName is testuser (no spaces - checked that)

strCN is 'Test User' (no other chars before or after and without the quotes of course)

5
  • updated information. Now getting error -2147016651 Commented Jun 5, 2015 at 7:38
  • Add Wscript.Echo err.source, err.description Commented Jun 5, 2015 at 8:21
  • @JosefZ just getting an emtpy message box with your line (Next line after ...<> 0) Then). Also tried Err.Description (seems the best variant in my eyes) and Err.description Commented Jun 8, 2015 at 8:35
  • VBScript commands, statements, variable names etc. are case insensitive. However, I consider your original question answered. For error code -2147016651 ask another question (best at serverfault.com imho). Add output from Wscript.Echo err.number & vbNewLine & err.source & vbNewLine & err.description & vbNewLine & Hex(err.number) there. Don't forget this echo needs to precede any (even implicit) err.clear Commented Jun 8, 2015 at 11:17
  • Resolved this also: It was a problem in my infrastructure... It was a Test-Copy of my 2003 DC. On a Win7-Client it showed "The server cannot compute your request" (translated DE->EN). I was not able to solve but I then ran it in our live environment using snapshots as backup and it worked correctly. I guess it was missing something. (we have 3 DCs, 2 DNS live and test was onle a DC and a Client with lmhosts and hosts entrys) Commented Jun 9, 2015 at 7:37

1 Answer 1

1

Poorly documented that On Error GoTo 0 statement calls the Clear method automatically. Therefore, use

'[...]
        objUser.sAMAccountName = strNTName
        On Error Resume Next
        objUser.SetInfo
        If (Err.Number <> 0) Then
            Wscript.Echo "Unable to create user with NT name: " & strNTName & " - Error-Code: " & Err.Number & " (sAMAccountName)"
            On Error GoTo 0
        Else
'[...]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Now I get error -2147016651 which is not really helpful, too. I'll edit my question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.