• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Create Local User Account specifying domain with VBS

I have a vbs script that works in creating a local user account as an administrator on a target computer. The only thing is that it creates it as a local admin if that computer as the domain. How can I specify a different domain, or should I say the domain of AD which would be "GVCC"
' get target machine name and password 
' from command line arguments 
strServer = wscript.arguments(0)
strUser = wscript.arguments(1)
strPwd = wscript.arguments(2) 
 
' connect to target machine and  
' create new user 
Set oServer = GetObject ("WinNT://" & strServer) 
Set oUser = oServer.Create ("user", strUser)

oUser.SetPassword strPwd 
oUser.SetInfo 

' add new user to 'Administrators' group 
Set Group = GetObject("WinNT://" & strServer & "/administrators,group") 
Group.Add(oUser.ADsPath) 
Group.Setinfo 
 
' release objects 
Set oServer = nothing 
Set oUser = nothing 
Set group= nothing

Open in new window

0
cbielich
Asked:
cbielich
  • 5
  • 3
1 Solution
 
OklahomaDaveCommented:
You are using the older WinNT ADSI provider, and as such it only references local machines. If you want to add an administrative account to your domain, you might want to explore using ADO to query your Active Directory server.
0
 
cbielichAuthor Commented:
I dont want to add an administrative account to my domain I want to add an domain users as an administrator of a local machine. Can ADO do this? Is there no option for this with the code I have now?
0
 
OklahomaDaveCommented:
Hi cbielich,

My apologies for misunderstanding. What you'll need to do is create one isntance of your WinNT ADSI provider that can talk to your domain, then another that talks to your local machine's Administrators group. Then, get the user you want from the domain instance, and add it to the Administrator group on the local box.

You would first set your oUser object to your desired domain account:

oUser  = GetObject('WinNT://GVCC/BobSmith, User")

Open in new window


You've already bound to the local group you want, so then just add the user to that group - and you've already done that! So you're 90% of the way there!

i hope this has helped!

-David


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
cbielichAuthor Commented:
Can you show me how I need to integrate that into my existing code please :)
0
 
OklahomaDaveCommented:
In the line where you set oUser, replace it with the line I provided and replace the "BobSmith" name with the name of the user you want to pull from the domain....

The difference here is that you're not creating a user, you're simply binding to an existing user that you can add to the local machine's administrator's group.
0
 
cbielichAuthor Commented:
So do I use "Set" before it?

I replaced the line with

Set oUser  = GetObject('WinNT://GVCC/strUser, User")

and I get this error

Microsoft VBScript compilation error: Syntax error
0
 
OklahomaDaveCommented:
Okay, it looks like I had a typo in that line. Replace the single-quote just before WinNT with a double-quote and try it again. Apologies for the goof.
0
 
OklahomaDaveCommented:
One other itme - You definitely need the "Set" keyword in front of the assignment. Any time you set a variable to an object reference in VBScript you need to use the Set keyword. You don't have to do it when you're setting regular values like strings or numbers.

-David
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now