I need help with this, as I can’t see what I’m doing wrong:
I’m wrote a VBScript file that unlocks a user from Active Directory. I got everything to work, but I wanted to add some error control to the script. So, I added the “On Error Resume Next” at the beginning of my script and then put in test conditions. Here is the code snippet:
set objUser = getobject(“WinNT://GTLAW/” & strusername & “,user”)
‘ Check to make sure username is valid
if err.number 0 then
wscript.echo(“Error accessing user: ” & strusername & ” — not found”)
wscript.quit
end if
The problem is when I ran this without the “on error resume next” the script would fail at the getobject line with an error window saying ” line 43, char 5, The user name could not be found, code 800708AD, source (null) “. Once you add the “On error” line, no error is generated and the script just ends — no error message, no anything.
Any ideas on how I should be properly testing in this instance?
I’m attaching the full script in case you need it for reference. Please go easy, as I am still learning the ropes ….
Thanks! Andrew
Here is the full script:
‘****************************************************************
‘ ADUnlock.vbs
‘
‘ Written by Andrew Harrell on 7/15/02
‘
‘ The script clears the “Account is Locked Out” flag for a specific user
‘ in Active Directory (for GTLAW)
‘
‘ The syntax for running this script is: cscript adunlock.vbs username
‘ where username is the person who’s account you are trying to unlock
‘
‘****************************************************************
option explicit
call main()
‘****************************************************************
‘* End of script
‘****************************************************************
‘****************************************************************
‘* Subs and Functions
‘****************************************************************
sub main
dim strusername
dim objUser
‘ Check for correct number of arguments in the command line
if wscript.arguments.count 1 then
wscript.echo “Syntax error: Usage is: cscript adunlock.vbs username”
wscript.quit
end if
strusername = wscript.arguments(0)
‘Now bind to the Active Directory user object
set objUser = getobject(“WinNT://GTLAW/” & strusername & “,user”)
‘ Check to make sure username is valid
if err.number 0 then
wscript.echo(“Error accessing user: ” & strusername & ” — not found”)
wscript.quit
end if
‘ Now test for a locked out status, and if locked go ahead and unlock
if objUser.IsAccountLocked = True then
wscript.echo(“User ” & strusername & ” is locked, now unlocking …”)
objUser.IsAccountLocked = False
objuser.SetInfo
if err.number0 then
wscript.echo (“Cannot Save Change to Active Directory — Possible Security Issue”)
wscript.quit
end if
wscript.echo(“User ” & strusername & ” has been unlocked!”)
else
wscript.echo(“User ” & strusername & ” is not locked out in Active Directory.”)
end if
end sub
‘****************************************************************