Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create user account in admin group 3

Status
Not open for further replies.

NJDEV1K

Programmer
Jan 10, 2004
19
US
I have used the script below successfully to create a user, is there a way to have the script make the user a member of the Administrators group when creating the account?

strComputer = "."
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", "USERNAME")
objUser.SetPassword "password"
objUser.SetInfo
 
I did find the below script to add a user to the admin group. Can the two be combined anyway?


strComputer = "."
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strComputer & "/USERNAME,user")
objGroup.Add(objUser.ADsPath)
 
strComputer = "."
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", "USERNAME")
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
objGroup.Add(objUser.ADsPath)
Set objGroup = Nothing
objUser.SetPassword "password"
objUser.SetInfo
 
I tried the script and it just errors saying the user cannot be added to the group because the user does not exist.
 
sorry try,

strComputer = "."
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", "USERNAME")
objUser.SetPassword "password"
objUser.SetInfo

Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
objGroup.Add(objUser.ADsPath)
Set objGroup = Nothing
 
It added the user but didn't make it a member of administrators. I appreciate your help on this.
 
MRMOVIE Ignore Last reply, Your script worked. I ran a different script by accident. You rock, thank you very much for your help.
 
One more little issue...
If I use strComputer = "." I get an error stating that the user does not exist so it can't be added to the group.

If I use strComputer = "Computername" with a computer name in it it runs fine. Is there a way to get it to work with the "."?????
Thanks


 
Hello NJDEVIK,

Retrieve the computername via script would do.
Code:
set wnt=createobject("wscript.network")
strComputername=wnt.Computername
set wnt=nothing
'proceed with the rest
regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top