Got an error with this script, cannot connect to computer... - TechRepublic
Question
June 15, 2007 at 05:40 AM
julliadarc

Got an error with this script, cannot connect to computer…

by julliadarc . Updated 19 years ago

PLEASE HELP!!!

The computer list was created manually.

‘——————————————————————————-
‘ Initialization – Declare variables
‘——————————————————————————-

Dim fsoIn, fsoOut
Dim inFile, outFile
Dim arrComputerNames
Dim objUser
Dim strComputer
Dim newPassword
Dim ErrorOccurred
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const inFilename = “computers.txt”
Const outFilename = “ChangePwdcomputers.log”

‘——————————————————————————-
‘ Main script
‘——————————————————————————-
On Error Resume Next
ErrorOccurred = False

‘ Insert WARNING here…
Msgbox (“WARNING: This script will change the local administrator password for every ” & _
“computer listed in computers.TXT. If any services are running with the local ” & _
“administrator credentials, those services must be updated, or they won’t ” & _
“start on the next boot. For this script to work, you must have administrative ” & _
“privileges on all of the remote computers you are changing the password for.”)

‘ Get new password
newPassword = Inputbox (“Please enter the new password.”)

‘ Open the input file and skip the header line
Set fsoIn = CreateObject(“scripting.filesystemobject”)
Set inFile = fsoIn.OpenTextFile(inFilename, ForReading, True)
inFile.Skipline

‘ Open the log file (append mode) and timestamp the entry
Set fsoOut = CreateObject(“scripting.filesystemobject”)
Set outFile = fsoOut.OpenTextFile(outFilename, ForAppending, True)
outFile.writeline (Now & vbTab & “Starting script…”)

While Not inFile.AtEndOfStream
arrComputerNames = Split(inFile.Readline, vbTab, -1, 1)
‘ arrComputerNames(0) contains the computer name
strComputer = arrComputerNames(0)

‘ Connect to the computer\administrator account
Set user = GetObject(“WinNT://” & temp & “/administrator,user”) ‘ local account to change password
If Err.Number <> 0 Then
outFile.writeline Now & vbTab & “Error connecting to ” & strComputer & ” — ” & Err.Description
Err.Clear
ErrorOccurred = True
Else
‘ Set the password for the account
objUser.SetPassword newPassword
objUser.SetInfo
If Err.Number <> 0 Then
outFile.writeline Now & vbTab & “Error setting password for ” & strComputer & _
“\Administrator” & ” — ” & Err.Description
Err.Clear
ErrorOccurred = True
Else
outFile.writeline (Now & vbTab & “Password set for ” & strComputer & “\Administrator”)
End If
End If
Wend

‘ Clean up the environment
outFile.writeline (Now & vbTab & “Ending script…”)
inFile.close
outFile.close

If ErrorOccurred Then
msgbox “Script completed with errors. Please check the log file.”
Else
MsgBox “Script completed successfully.”
End If

This discussion is locked

All Comments