Error handling problem.
- From: "Brian Free" <bfree@xxxxxxxxxxxxxx>
- Date: Thu, 31 Mar 2005 11:14:02 -0700
I have written a script that queries a specified OU and then resets the
administrator password for the local machine account of all of the computers
in the OU. The script appears to be working fine, but I'm having a problem
with the error handling. For a reason I can't determine, when a computer is
offline the error isn't reported until the next time through the loop, so
the computer reported in error is actually fine, but the computer before it
that doesn't get logged as a success or an error was actually in error. I
can't figure out why Err doesn't get set until after the sub completes. Any
help would be greatly appreciated. Below is the sub in use. I can provide
the entire script if needed, but felt it would be too much to take in if I
posted the whole thing right off.
Thanks in advance,
Brian Free
Sub ChangePassword()
' Connect to the computer\administrator account
Set objUser = GetObject("WinNT://" & strComputer & "/Administrator, user")
If Err.Number <> 0 Then
outFile.writeline Now & vbTab & "Error connecting to " & strComputer &
" --- " & Err.Description
errorFile.writeline strComputer
j = j + 1 'Add 1 to failed count
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
errorFile.writeline strComputer
j = j + 1 'Add 1 to failed count
Err.Clear
ErrorOccurred = True
Else
outFile.writeline (Now & vbTab & "Password set for " & strComputer &
"\Administrator")
successFile.writeline (strComputer)
i = i + 1 'Add 1 to the success count!
End If
End If
End Sub ' ChangePassword
.
- Follow-Ups:
- Re: Error handling problem.
- From: Joe Earnest
- Re: Error handling problem.
- Prev by Date: Re: Convert Hex Value to Date from Binary Reg Key
- Next by Date: Re: Error handling problem.
- Previous by thread: Re: ACE Mask
- Next by thread: Re: Error handling problem.
- Index(es):
Relevant Pages
|