Richard
Mon Nov 13 13:01:41 CST 2006
VBScript programs are very difficult to troubleshoot if normal error
handling is turned off with "On Error Resume Next". Sometimes you even get
erroneous results. I like to turn off normal error handling only for the
statement I expect could raise an error, then handle the error, then restore
normal error handling. The statement "On Error GoTo 0" simply restores the
default error handling. It does not go anywhere. By habit I add this to both
If conditions. This way I immediately spot the typo's I seem to frequently
introduce (even in the error handling code). I'd rather spot the error and
fix it.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab -
http://www.rlmueller.net
"chief123" <chief123@discussions.microsoft.com> wrote in message
news:ECE0634E-78A6-44F8-AD2F-0FDEF3C66E42@microsoft.com...
> Looks like it works great. What does the "On Error Goto 0" accomplish? It
> would seem that would check you out of the If statement, but there is a
> second one outside the IF....
>
> "Richard Mueller" wrote:
>
>> chief123 wrote:
>>
>> >I need to be able to check for the existence of a specific local user
>> >account
>> > on our workstations. If the account does not exist, I want to run the
>> > rest
>> > of
>> > my script that will add this account, set its password, and add the
>> > account
>> > to the local administrators group.
>> >
>> > I already have the script put together to add the account, etc. I just
>> > need
>> > to know the best way to check for the existence of this account, first.
>> > If
>> > it
>> > exists, I want to skip the rest of the script and close out.
>>
>> You can attempt to bind to the user object and trap the possible error.
>> For
>> example:
>> ===========
>> strComputer = "MyComputer"
>>
>> On Error Resume Next
>> Set objUser = GetObject("WinNT://" & strComputer & "/TestUser,user")
>> If (Err.Number <> 0) Then
>> ' The user does not exist.
>> On Error GoTo 0
>> ' Perform actions to create user and add to Administrators group.
>> End If
>> On Error GoTo 0
>> ' Continue with other tasks.
>>
>> --
>> Richard
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab -
http://www.rlmueller.net
>>
>>
>>