Error handling problem.



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


.



Relevant Pages

  • Re: Problem disabling and deleting AD Account
    ... 'Sub to intialise and load the HTA Script Window. ... 'Sub to search for the AD account and then disable it using input ... UserCn = ltrim)) ...
    (microsoft.public.windows.server.scripting)
  • Problems with Account Deletion Script
    ... Here is the Script Code I am currently using: ... 'Sub to intialise and load the HTA Script Window. ... 'Sub to search for the AD account and then disable it using input from ... intUbound = Ubound ...
    (microsoft.public.scripting.vbscript)
  • Protecting against dDOS bots (was: Newbie php problem)
    ... The form mail script posted that was used, ... requires the applicant to pass some kind of Turing test, ... Turing test if the account balance ever drops to zero. ... Log into the same account repeatedly, which consumes your credit ...
    (alt.php)
  • Re: Detecting is hyperthreading is enabled with WMI?
    ... It is too bad that WMI does not give this info. ... have to be done to the script. ... Public Sub DisplayProcessorInfo ... dim ProcessorSet, Processor ...
    (microsoft.public.windowsxp.wmi)
  • Re: Entourage account setup applescript not working
    ... I pasted the script at the end just in case. ... When comparing the account settings on 2 computers, ... This script assists a user with the setup of his Exchange account ... Customize the network and server properties below with information ...
    (microsoft.public.mac.office.entourage)