Computing.Net > Forums > Programming > VBS adding local users to computers

VBS adding local users to computers

Reply to Message Icon

Original Message
Name: matter
Date: May 7, 2007 at 23:47:21 Pacific
Subject: VBS adding local users to computers
OS: win xp
CPU/Ram: 3400+AMD 1.5GB RAM
Model/Manufacturer: Winfast
Comment:

i am trying to make a vbs add users to the local administrator group from a list of computers stored on a text file. here is what i have so far:

option explicit

const COMP_FILE = "computers.txt"
const FOR_READING = 1

dim fso, ts, strMac, strCommand

set wshShell = createObject("WScript.shell")
set fso = createObject("scripting.filesystemobject")
set ts = fso.opentextfile(COMP_FILE, FOR_READING)
do until ts.atendofstream
strMac = ts.readline
strComputer = addColons(strMac)

function addColons(str)
dim i, temp

temp = mid(str, 1, 2)
for i = 3 to 11 step 2
temp = temp & ":" & mid(str, i, 2)
next
addColons = temp
end function
'
Loop

Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
Set objUser = GetObject("WinNT://domain/user")
objGroup.Add(objUser.ADsPath)

i got these from examples and dont know all that much of vbs language.


any help would be appreciated

Mathew


Report Offensive Message For Removal

Response Number 1
Name: Razor2.3
Date: May 8, 2007 at 20:04:06 Pacific
Subject: VBS adding local users to computers
Reply: (edit)

Wait, what are you asking for? Do you need to make this account on the PC list and assign it to the administrator group? Does the user already exist? Why are you adding colons?


Report Offensive Follow Up For Removal

Response Number 2
Name: matter
Date: May 9, 2007 at 01:27:32 Pacific
Subject: VBS adding local users to computers
Reply: (edit)

lol as i said, i dont know that much of vbs.
i wrote the bottom bit after loop, and i got the reading from text file from another script.
the idea is to get the vbs to read a text file, which has all the names of the computers in that text file.
then go to those computers, add a domain member to the local administrators group.

i dont know what colons are.

i just realised the topic of this is "local users to computers" my bad, its adding domain users to local administrators group.



Report Offensive Follow Up For Removal

Response Number 3
Name: Razor2.3
Date: May 9, 2007 at 20:18:24 Pacific
Subject: VBS adding local users to computers
Reply: (edit)

All right, I'm still not sure if you want to create a new user and assign him to the local Administrators, or if you want to do it with an NT4 domain user, or an Active Directory user. I'm going to assume the later.

I haven't tried to see if this works, but the AD part comes from Microsoft's script repository, and the rest of it comes from a script I used in the past (which was also biased off of the script repository).

This board's word wrapping is a pain; I'm still not sure if it'll wrap lines and break code.

Usage: Save this script as whatever.vbs, then drag and drop your file of computer names on the script.

Script assumes one line = one computer.

You'll need to replace the LDAP line with the user in question.
Code Begins:

Option Explicit
Dim sOutput
Dim oUser, oGroup

sOutput = "Results:" & vbNewLine
Set oUser = _
GetObject("LDAP://cn=Razor23,OU=is,dc=really,dc=great,dc=com")

With _
CreateObject("Scripting.FileSystemObject").OpenTextFile(WScript.Arguments(0))
On Error Resume Next
Do Until .AtEndOfStream
Set oGroup = GetObject("WinNT://" & Trim(.ReadLine) _
& "/Administrators,group")
oGroup.Add(oUser.ADsPath)

If Err.Number = 0 Then
sOutput = sOutput & sComputer & " DONE" & vbNewLine
Else
sOutput = sOutput & sComputer & " ERROR" & vbNewLine
Err.Clear
End If
Loop
End With
WScript.Echo sOutput



Report Offensive Follow Up For Removal

Response Number 4
Name: matter
Date: May 9, 2007 at 21:55:51 Pacific
Subject: VBS adding local users to computers
Reply: (edit)

that script look good! makes my script look like it was made from a 4 year old... thanks!

i have figured out another way of doing it, instead of getting the computer names from a text file:

Dim strComputer1, strComputer2, objGroup, objUser, objGroup1, objUser1
strComputer1 = "netbiosnameExample"
strComputer2 = "ComputerNameExample"

Set objGroup = GetObject("WinNT://" & strComputer1 & "/Administrators")
Set objUser = GetObject("WinNT://domainexample/user")
objGroup.Add(objUser.ADsPath)

Set objGroup1 = GetObject("WinNT://" & strComputer2 & "/Administrators")
Set objUser1 = GetObject("WinNT://domainExample/user")
objGroup1.Add(objUser.ADsPath)

but there are about 20 computers that need a ADUC network structure user account, or domain user added to the local administrators to each computer.

thanks again ill try it out and let you know!


Report Offensive Follow Up For Removal

Response Number 5
Name: matter
Date: May 9, 2007 at 22:58:38 Pacific
Subject: VBS adding local users to computers
Reply: (edit)

omg this script is da best!!!!
it works like a charmed!
i wasnt sure about the line:
GetObject("LDAP://cn=Razor23,OU=is,dc=really,dc=great,dc=com")

so i changed it to:
GetObject("WinNT://domainExample/UserExample")

thanks again!


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: VBS adding local users to computers

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software