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

Posted on 2006-04-26
Medium Priority
Last Modified: 2008-02-01

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")

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?

Question by:The_Dark_Rabbit
  • 2
  • 2
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 16550715

Here is a fine source code
hope this will help you


Author Comment

ID: 16550761
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.


LVL 71

Accepted Solution

Chris Dent earned 1600 total points
ID: 16551480

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


Author Comment

ID: 16558729
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.


LVL 71

Expert Comment

by:Chris Dent
ID: 16560146

Glad I could help :)


Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question