We help IT Professionals succeed at work.

VBS Reading Null Value in AD User Account wWWHomePage Attribute

I'm trying to get the ppt to start if there is no value in the wWWHomePage attribute. I keep getting an error: The directory property cannot be found in the cache. I've tried several different call outs for IsNull or Empty.

Dim objSysInfo ,objUser ,strwWWHomePage,strUserDN,ppt, strMbox

Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserDN)

strwWWHomePage = objUser.Get("wWWHomePage")
If IsNull(strwWWHomePage) or strwWWHomePage = Empty Then

Set ppt = CreateObject("PowerPoint.Application")
  strMbox = MsgBox("Click OK to start PowerPoint presentation")
  ppt.Visible = True
  ppt.Presentations.Open "\\serverxx\tracking\ppt.ppsx"
 
Else
  wscript.quit

End If
Comment
Watch Question

PowerShell Developer
Top Expert 2010
Commented:

Your only choice for that one is On Error Resume Next. There's no way to test for a null property in AD using VbScript and ADSI I'm afraid.

Something like this.

Chris
' Enable error handling
On Error Resume Next
' First command resets the value of the variable to ""
' Second attempts to set it with the value form AD
' If the second fails the variable will still be set to ""
strwWWHomePage = "" : strwWWHomePage = objUser.Get("wWWHomePage")
' Disable error handling
On Error Goto 0

' Test the value in the variable
If strwWWHomePage = "" Then
  Set ppt = CreateObject("PowerPoint.Application")
  strMbox = MsgBox("Click OK to start PowerPoint presentation")
  ppt.Visible = True
  ppt.Presentations.Open "\\serverxx\tracking\ppt.ppsx"
End If

Open in new window

Author

Commented:
Perfect!