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

adding user to local computer group

Status
Not open for further replies.

Kendals

Technical User
May 21, 2002
8
GB
hi, I have a text file with usernames how can i script this to add them to a local group on my pc
 
have a look at the WinNT provider

Set objGroup = GetOBject("Winnt://" & strComputerName & "/Administrators,group")

, or be really socks and sands and try one of hte command lines tools, net localgroup "administrators" username add...or something like that
 
Quick and dirty using an old script I had:

Code:
'Adds users to local groups on computers

'Constants for text file manipulation
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Open and read the list of users
Set objUserFile = objFSO.OpenTextFile ("Users.txt", ForReading)
strText = objUserFile.ReadAll
objUserFile.Close

'Split list of users into an array and then clear the string
arrUsers = Split(strText, vbCrLf)
Set strText = Nothing

Set objWshNet = CreateObject("WScript.Network")

strDomain = objWshNet.UserDomain
strComputer = objWshNet.ComputerName
strGroup = "Administrators"

Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group")

For each strUser in arrUsers

	'Configure to add a domain user to the Local Administrators Group
	Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser)

	'If not already a member, add the user to the local Administrators group:
	If Not objGroup.IsMember(objUser.ADsPath) Then
		objGroup.Add(objUser.ADsPath)
	End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top