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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding domain users to local groups

Status
Not open for further replies.

JanEric

Programmer
Joined
May 26, 2005
Messages
2
Location
US
I need to take a local group that exists on a computer, and add to it a user that is in a different domain.

I can do this using Local Users and Groups (lusrmgr.msc): I select the Properties for the desired group, click the Add button, enter the user in the form of Domain\User, and click OK. At this point I get prompted to enter the username and password of an account with access rights to the specified domain. I then enter my NT username and password and the user gets added to the local group.

I want to automate this process using VB Script or VB6. I've tried code like the following:

strComputer = "RemoteComputer"
strGroup = "LocalGroup"
strPath = "Domain/User"
Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup,group")
Set objUser = GetObject("WinNT://" & strPath & ",user")
objGroup.Add(objUser.ADsPath)

I keep getting a "user not found" error when I try to set objUser. I assume this is because there is no provision to enter a username/password, like I can in Local Users and Groups, which would give the script the rights to browse users in another domain. Anyone know how I can remedy this? I don't care what method is used, although I would prefer something that can be used remotely.

I think there might be a way using LDAP, though I'm not very experienced with it, and don't really follow how you define paths in it (all that "OU=, CN=" stuff).

Thanks
 
Actually there is a simple command you can run at the client to do this.

Take a look at Net Localgroup.

I've used Sysinternals PSEXEC to execute it on remote machines and it works great.


I hope you find this post helpful.

Regards,

Mark
 
Worked like a charm. No permission problems, and it can be done from a script. Exactly what I wanted.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top