Error Checking (VBScript)

This code can be found in Chapter 21 of Active Directory, 3rd Edition

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' From the book "Active Directory, Third Edition" 
' ISBN: 0-596-10173-2

On Error Resume Next
   
'**********************************************************************
'Clear errors
'**********************************************************************
Err.Clear
   
'**********************************************************************
'Get a pointer to the Administrator account
'**********************************************************************
Set objUser = GetObject ("LDAP://cn=Administrator,cn=Users,dc=mycorp,dc=com")
If Hex(Err.Number)="&H80005000" Then
  WScript.Echo "Bad ADSI path!" & vbCrLf & "Err. Number: " _
    & vbTab & CStr(Hex(Err.Number)) & vbCrLf & "Err. Descr.: " _
    & vbTab & Err.Description
  WScript.Quit
End If
   
'**********************************************************************
'Explicitly call GetInfo for completeness
'**********************************************************************
objUser.GetInfo
   
'**********************************************************************
'Clear any previous errors
'**********************************************************************
Err.Clear
   
'**********************************************************************
'Try and get a pointer to the "moose" attribute of the user (which
'doesn't exist)
'**********************************************************************
x = objUser.Get("moose")
   
'**********************************************************************
'Check for property does not exist error
'**********************************************************************
If Hex(Err.Number)="&H8000500D" Then
  WScript.Echo "No such property!" & vbCrLf & "Err. Number: " _
    & vbTab & CStr(Hex(Err.Number)) & vbCrLf & "Err. Descr.: " _
    & vbTab & Err.Description
End If

This code has been viewed 2423 times.

New from the creators of TechTasks.com: StatSheet.com