Script issue

Peter_1985 2,736 Reputation points
2022-02-03T15:39:32.203+00:00

Hi,
How to resolve issue below

C:\dp2\L0\Feb>cscript S1.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

C:\dp2\L0\Feb\S1.vbs(7, 1) (null): The server is not operational.

due to the last line in the following?

Option Explicit
Dim strUser
Dim objRootLDAP, objContainer, objNewUser
strUser = "User0"

'Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://127.0.0.1")

Microsoft 365 and Office | Development | Office JavaScript API
Microsoft 365 and Office | Development | Other
Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 60,161 Reputation points
    2022-02-04T16:07:11.07+00:00

    Here's a VBS version that adds a local user. Note that LDAP is for AD but for a local user you're adding to the local user store so WinNT.

    Option Explicit
    
    Sub AddLocalUser ( computerName, userName, password )
       Dim computer
       Set computer = GetObject("WinNT://" & computerName)    
    
       Dim user
       Set user = computer.Create("user", userName)
       user.SetPassword password
       user.SetInfo   
    End Sub
    
    Function GetComputerName ()
       Dim shell
       Set shell = CreateObject("WScript.Network")
    
       GetComputerName = shell.ComputerName
    End Function
    
    AddLocalUser GetComputerName(), "test", "testingPassword"
    

1 additional answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2022-02-03T15:58:42.153+00:00

    Has this script ever worked? You're using the loopback IP address. I've never tried using an IP address but if it works that would mean you need to run this script on a domain controller. The more common case is to use rootDSE.

    Set objRootLDAP = GetObject("LDAP://rootDSE").Get("defaultNamingContext")
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.