question

Jackson1990-7147 avatar image
0 Votes"
Jackson1990-7147 asked cooldadtx commented

Script issue

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")

office-vba-devoffice-scripts-excel-devoffice-js-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cooldadtx avatar image
0 Votes"
cooldadtx answered cooldadtx commented

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"
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

For comparison, here's the Powershell equivalent.

$userName = "test"

# Should collect this using Read-Host secure or equivalent, not hard code...
$password = "testingPassword"
$encryptedPassword = ConvertTo-SecureString $password -AsPlainText

New-User -Name $userName -Password $encryptedPassword
0 Votes 0 ·

Hi,
In Win server, is there one place to see all users created/available?

0 Votes 0 ·
cooldadtx avatar image cooldadtx Jackson1990-7147 ·

In the UI? Yes, just like Win10 you can use the MMC. In the search/run box type lusrmgr.msc. That should open the local users & groups app. If that doesn't work then use mmc.exe to start it. Then go to File\Add & Remove Snap ins. Scan for Local Users & Groups and add it. You can then see the local users and groups on the machine. Note that if this is a DC then it might not work as I don't know if you can have local users on a DC.

0 Votes 0 ·
cooldadtx avatar image
0 Votes"
cooldadtx answered Jackson1990-7147 commented

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")
· 9
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,
I still get

Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

C:\dp2\L0\Feb\S1.vbs(8, 1) (null): The specified domain either does not exist or could not be contacted.

due to the last line below

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

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


0 Votes 0 ·
cooldadtx avatar image cooldadtx Jackson1990-7147 ·

Are you actually running on a domain computer?

0 Votes 0 ·

Yes, there is existing domain to the server.

0 Votes 0 ·
Show more comments