Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

vbscript - How to trap error for empty directory property variable error 8000500D

In a script that retrieves user attributes from active directory, there is one attribute that is sometimes empty, but I can't seem to trap the error for when it is empty. IsNull, IsObject, IsEmpty, and IsBlank do not seem to be able to catch it. Every time I run the script, I get the error the directory property cannot be found in the cache with the code 8000500D

Is there a way that I can trap that error?

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshEnvironment = WshShell.Environment("process")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & ADSysInfo.UserName)
strFax = ""
    'check if fax number exists. Throw warning message if missing
    If IsObject(objUser.FaxNumber) and Not isNull(objUser.FaxNumber)
        If Not IsBlank(objUser.FaxNumber) Then
            strFax = objUser.FaxNumber
        Else
            MsgBox "Please be aware that the fax number is missing", vbExclamation, "Attribute Missing"
        End If
    End If

[edit]: Would this be the best way to trap the error, and also allow other unrelated errors to be thrown normally?

On Error Resume Next
    strFax = objUser.FaxNumber
    If Err.Number <> 0 Then
        MsgBox "Please be aware that the fax number is missing", vbExclamation, "Attribute Missing"
        Err.clear()
        strFax=""
    End If
on error goto 0
question from:https://stackoverflow.com/questions/66049842/how-to-trap-error-for-empty-directory-property-variable-error-8000500d

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Would this be the best way to trap the error, and also allow other unrelated errors to be thrown normally?

On Error Resume Next
    strFax = objUser.FaxNumber
    If Err.Number <> 0 Then
        MsgBox "Please be aware that the fax number is missing", vbExclamation, "Attribute Missing"
        Err.clear()
        strFax=""
    End If
on error goto 0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...