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.

Re: create user account in windows by Slim

Slim
Mon Dec 11 06:42:44 CST 2006

http://dev.thatsit.net.au/samples/wsh/ad/users/manage/usmgvb05.htm


"Uncle Sam" <sameervijaykar@gmail.com> wrote in message
news:1165837541.944047.273330@j44g2000cwa.googlegroups.com...
>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.
>



Re: create user account in windows by Richard

Richard
Mon Dec 11 09:47:40 CST 2006

In your snippets, the value of the variable sNewUser is the name of the user
objects being created. This is the value passed to the Create method. This
value must be unique in the computer. The value assigned to the Fullname
property does not identify the object. The value does not need to be unique
and can even be missing. It corresponds to the display name of the object.

Your second snippet fails because the object with name "mini-strator"
already exists. To create a new user, make sure the value you pass to the
create method (the value of sNewUser in your code) is unique.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"Uncle Sam" <sameervijaykar@gmail.com> wrote in message
news:1165837541.944047.273330@j44g2000cwa.googlegroups.com...
>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.
>



Re: create user account in windows by Uncle

Uncle
Mon Dec 11 12:13:14 CST 2006

Thank You. By the way, I later found out that windows has an in-built
command for creating users:
net user <username> <password> /add /active:<yes><no>
So there is actually no need of the whole the whole script above.
Anyway, thank you.