Using WSH (VB) to add a domain user to local administrator's group under Windows XP/2003

Hi,

I'm working on a script that I want to be able to run on my admin station and do the following:

- Query user for a domain user account name (service account)
- For each workstation(XP) on a list, add that domain user to the local administrator's group

I've tried:
strComputer = [computer name variable]
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")

Set objUser = GetObject("WinNT://" & strComputer & "/" & [user name variable] & ",user")
objGroup.Add(objUser.ADsPath)

I also tried with:
Set objUser = GetObject("WinNT://" & strComputer & "/DOMAIN\" & [user name variable] & ",user")

I get a "Exception: Unknown Exception" error every time... I know that this is probably because I'm trying to change a domain account instead of a local account, but I can't find any info on how I would do this for a domain account.  Any suggestions?

And yes, the user executing the script has full administrative privilages  on the target machines.

And yes, I'm kind of new to programming this kind of script, why do you ask?

Cheers!
The_Dark_RabbitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shiju SasidharanAssoc Project ManagerCommented:

Here is a fine source code
hope this will help you
http://vbnet.mvps.org/index.html?code/network/openuserbrowser.htm

0
The_Dark_RabbitAuthor Commented:
Thanks for the quick response.  However, the code you pointed me to seems a little inpenetrable to me (as I mentioned, I'm a beginner).  I'm not sure which bits are useful to me.  If someone could help me find the bit I need on that page so that I can find a way to integrate it into my script (which actually does a few other tasks as well), then your link might be useful.  Otherwise, I'm looking for a quick piece of code, not a whole script.

Cheers,

TDR
0
Chris DentPowerShell DeveloperCommented:

If you're trying to add a Domain User to a Local Security Group then this is probably where it's breaking:

Set objUser = GetObject("WinNT://" & strComputer & "/" & [user name variable] & ",user")

The statement is telling your script to connect to a Local User Account on strComputer - which won't exist.

Instead you would need to do:

Set objUser = GetObject("WinNT://" & strDomain & "/" & strUserName & ", user")

Where strDomain is your NetBIOS Domain Name. You can get that programatically as well:

Set objNetwork = CreateObject("WScript.Network")
strDomain = objNetwork.UserDomain

Chris
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The_Dark_RabbitAuthor Commented:
Thanks a lot, Chris!  That's exactly what I was looking for.  I feel kind of dumb for not figuring that one out, but I am grateful nonetheless.

Cheers,

TDR
0
Chris DentPowerShell DeveloperCommented:

Glad I could help :)

Chris
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.