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

Discussion in 'Scripting' started by Jason, Dec 6, 2005.

  1. Jason

    Jason Guest

    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
    Jason, Dec 6, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael

    %computername% to computername.txt

    Michael, Jan 19, 2004, in forum: Scripting
    Replies:
    1
    Views:
    437
    David H. Lipman
    Jan 19, 2004
  2. BNichols
    Replies:
    3
    Views:
    875
    Torgeir Bakken \(MVP\)
    Jan 11, 2005
  3. mrve

    computername and mac address

    mrve, May 2, 2006, in forum: Scripting
    Replies:
    0
    Views:
    147
  4. Erik van ''''t Hof

    script to change computername into assettag

    Erik van ''''t Hof, Sep 21, 2006, in forum: Scripting
    Replies:
    2
    Views:
    474
    Erik van ''''t Hof
    Sep 22, 2006
  5. Banji ajiye
    Replies:
    4
    Views:
    943
    Lanwench [MVP - Exchange]
    Nov 6, 2008
Loading...

Share This Page