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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBS adding local users to computers

Reply to Message Icon

Name: matter
Date: May 7, 2007 at 23:47:21 Pacific
OS: win xp
CPU/Ram: 3400+AMD 1.5GB RAM
Product: 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



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: May 8, 2007 at 20:04:06 Pacific
Reply:

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?


0

Response Number 2
Name: matter
Date: May 9, 2007 at 01:27:32 Pacific
Reply:

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.



0

Response Number 3
Name: Razor2.3
Date: May 9, 2007 at 20:18:24 Pacific
Reply:

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



0

Response Number 4
Name: matter
Date: May 9, 2007 at 21:55:51 Pacific
Reply:

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!


0

Response Number 5
Name: matter
Date: May 9, 2007 at 22:58:38 Pacific
Reply:

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!


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

renaming with dos? Script for XP



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VBS adding local users to computers

User input from VB script and pass to Bat www.computing.net/answers/programming/user-input-from-vb-script-and-pass-to-bat/20001.html

Add users to www.computing.net/answers/programming/add-users-to-/1246.html

Batch file to compute size of dir www.computing.net/answers/programming/batch-file-to-compute-size-of-dir/14387.html