Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > VB script for adding local users fail on IP-address success on computername

Reply
Thread Tools Display Modes

VB script for adding local users fail on IP-address success on computername

 
 
Jason
Guest
Posts: n/a

 
      12-06-2005
Hi,
I have a script that creates local accounts on computers defined in a
textfile. It works fine when I have computernames in the file but if I have
IP
addresses in the textfile it only creates the account user2 but fails to add
it to the local Administrators group. I can't understand why. Se code below.
Regards Jason

strDir = ".\"
strFailed = (".\failed.txt")
strSuccess = (".\success.txt")
Set objFile = objFSO.CreateTextFile(strDir & strFailed)

If objFSO.FileExists(strDirectory & strSuccess) Then
Set objFolder = objFSO.GetFolder(strDir)
Else
Set objFile = objFSO.CreateTextFile(strDir & strSuccess)
End If
set fsomain=createobject("scripting.filesystemobject")

Const ForAppending = 8
set objFile = nothing
set objFolder = nothing

Set failedmachines = objFSO.OpenTextFile(strDir & strFailed, ForAppending,
False)
Set successmachines = objFSO.OpenTextFile (strDir & strSuccess,
ForAppending, True)

Dim txtcomputername
Dim passwrd

On Error Resume Next

set machines=fsomain.opentextfile(".\pcs.txt")

Do While not machines.AtEndOfLine
txtcomputername = machines.ReadLine

Set colAccounts = GetObject("WinNT://" & txtcomputername & "")
Set objUser = colAccounts.Create("user", "user2")
objUser.SetPassword "8520"
objUser.SetInfo

Set objGroup = GetObject("WinNT://" & txtcomputername &
"/Administrators,group")
Set objUser = GetObject("WinNT://" & txtcomputername & "/user2,user")

objGroup.Add(objUser.ADsPath)
If Err Then
HandleErr()
Else
successmachines.WriteLine txtcomputername & "lyckades"
nCount = nCount + 1
End If
loop

Sub HandleErr()
failedmachines.WriteLine txtcomputername & " " & "failed " & Err.Number
Err.Clear
End Sub

txtdata.close
failedmachines.close
successmachines.close

MsgBox nCount & " computers updated"

set fsomain=nothing
set txtdata=nothing
set usr=nothing
set dellasset=nothing


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Find ComputerName via script as alternative to RDP? Pegasus \(MVP\) Scripting 0 09-05-2008 03:40 PM
script to change computername into assettag Erik van ''''t Hof Scripting 2 09-22-2006 07:05 AM
Login script to exit based on Computername. BNichols Scripting 3 01-11-2005 02:37 PM
%computername% to computername.txt Michael Scripting 1 01-19-2004 06:03 PM