I need a vbscript to create user accounts on a windows computer. Its is
a completely local computer, no domain or anything. I saw this script
on Google groups and found that it works for creating 1 user.
----------------------------------------------------------------------------------------------------------------------------------------------
sNewUser = "mini-strator"
sGroupname = "Users"
Set oWshNet = CreateObject("WScript.Network")
sComputerName = oWshNet.ComputerName
Set oComputer = GetObject("WinNT://" & sComputerName)
Set oUser = oComputer.Create("user", sNewUser)
On Error Resume Next
' save the user
oUser.Setinfo
' If user exists already, we get an error
If Err.Number = 0 Then
On Error Goto 0
oUser.SetPassword "1234"
oUser.Fullname = "John"
oUser.Description = "hi!"
oUser.Setinfo
End If
On Error Goto 0
' Add the user to the group
Set oGroup = GetObject("WinNT://" & sComputerName & "/" & sGroupname)
' Use error handling in case he is a member already
On Error Resume Next
oGroup.Add(oUser.ADsPath)
On Error Goto 0
----------------------------------------------------------------------------------------------------------------------------------------------
However if I change the username and try to create another user, it
doesn't work. For example if I run the above script once, then change
it to:
----------------------------------------------------------------------------------------------------------------------------------------------
sNewUser = "mini-strator"
sGroupname = "Users"
Set oWshNet = CreateObject("WScript.Network")
sComputerName = oWshNet.ComputerName
Set oComputer = GetObject("WinNT://" & sComputerName)
Set oUser = oComputer.Create("user", sNewUser)
On Error Resume Next
' save the user
oUser.Setinfo
' If user exists already, we get an error
If Err.Number = 0 Then
On Error Goto 0
oUser.SetPassword "1234"
oUser.Fullname = "Betty"
oUser.Description = "hi!"
oUser.Setinfo
End If
On Error Goto 0
' Add the user to the group
Set oGroup = GetObject("WinNT://" & sComputerName & "/" & sGroupname)
' Use error handling in case he is a member already
On Error Resume Next
oGroup.Add(oUser.ADsPath)
On Error Goto 0
----------------------------------------------------------------------------------------------------------------------------------------------
It does not create a new user with the name Betty, just a user named
John. Someone please help me with this. I need it urgently.