I'm trying to use the fnLDAPQuery to retrieve the SIP address of a user account. All my user user accounts have the field filled in, and is verified via the AD Users and Computers, however I have several computers that show the SIP address as "" (None).
Any idea what would cause this? It works fine on 98% of the machines, just a few. Both XP and W2K.
Any insight would be awsome.
*** Edit ***
I added some error checking, this is what happens on a machine that doesn't work.

Thanks,
Chris
Code:
Function fnLDAPQuery($What,Optional $From,Optional $Filter,Optional $OrderBy,Optional $Scope,
Optional $User,Optional $Pswd)
Dim $oCon,$oCMD,$oRS,$sQ,$aR,$C,$R
$sQ="<"+IIf($From="","LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext"),
$From)+">;"+$Filter+";"+IIf(VarType($What)>8192,Join($What,','),$What)+";"+
IIf($Scope<>"base" And $Scope<>"onelevel","subtree",$Scope)
$oCon=CreateObject("ADODB.Connection")
$oCon.Provider="ADsDSOObject"
$oCon.Properties("Encrypt Password").Value=1
$oCon.Properties("ADSI Flag").Value=1
If $User And $Pswd
$oCon.Properties("User ID").Value=$User
$oCon.Properties("Password").Value=$Pswd
EndIf
$oCon.Open("Active Directory Provider")
$oCMD=CreateObject("ADODB.Command")
$oCMD.ActiveConnection=$oCon
$oCMD.CommandText=$sQ
$oCMD.Properties("Page Size").Value=1000
$oCMD.Properties("Timeout").Value=30
$oCMD.Properties("Cache Results").Value=0
If InStr($OrderBy,"distinguishedName")
$oRS=CreateObject("ADODB.Recordset")
$oRS.CursorLocation=3
$oRS.Sort=$OrderBy
$oRS.Open($sQ,$oCon,0,1,1)
Else
If $OrderBy
$oCMD.Properties("Sort On").Value=$OrderBy
EndIf
$oRS=$oCMD.Execute
EndIf
If @ERROR Exit @ERROR EndIf
If $oRS.BOF And $oRS.EOF Exit @ERROR EndIf
$aR = $oRS.GetRows()
Dim $aFR[Ubound($aR,2),Ubound($aR,1)]
For $R=0 to Ubound($aR,2)
For $C=0 to Ubound($aR,1)
$aFR[$R,$C]=$aR[$C,$R]
Next
Next
$fnLDAPQuery=$aFR
EndFunction
Function GetSIP
; Example for getting the distinguishedName of a user
$sWhat = "msRTCSIP-PrimaryUserAddress"
; Use ANR (ambiguous name resolution)
$sFilter = "(&(objectClass=user)(anr="+@USERID+"))"
$aResults = fnLDAPQuery($sWhat,,$sFilter)
If @ERROR <> 0
$msg = MessageBox("Error: " + @ERROR + " - " + @SERROR,"Notice",16)
EndIf
;@ERROR " | " @SERROR ??
For $r = 0 to Ubound($aResults,1)
For $c = 0 to Ubound($aResults,2)
$sip = $aResults[$r,$c]
Next
; ?
Next
If $sip = ""
; $frmMain.TopMost = 0
$msg = MessageBox ("Your username is: " + '"' + @USERID + '"' + @CRLF +
"Your SIP address is: " + '"' + $sip + '"' + @CRLF +
"Local Version is: " + $LocalMessengerVersion,"Notice",48)
; $frmMain.TopMost = 1
Exit
Else
$sip = SubStr($sip, Len($sip) - Len($sip) + 5,)
; $frmMain.TopMost = 0
$msg = MessageBox ("Your username is: " + '"' + @USERID + '"' + @CRLF +
"Your SIP address is: " + '"' + $sip + '"' + @CRLF +
"Local Version is: " + $LocalMessengerVersion,"Notice",48)
; $frmMain.TopMost = 1
EndIf
EndFunction
Function MessengerDefaults
$MessengerReg = "HKCU\Software\Microsoft\MessengerService"
$rc = WriteValue($MessengerReg, "UserMicrosoft RTC Instant Messaging", $sip, "REG_SZ")
$rc = WriteValue($MessengerReg, "RTCState", "01000000", "REG_BINARY")
$rc = WriteValue($MessengerReg, "IMSBHide", "01000000", "REG_BINARY")
$rc = WriteValue($MessengerReg, "CEIP Preference", "0", "REG_DWORD")
$MessengerReg = "HKLM\Software\Microsoft\MessengerService"
$rc = WriteValue($MessengerReg + "\Policies","IMWarning","Welcome to Instant Messaging.", "REG_SZ")
EndFunction
Function WindowsMessenger($Method)
If InStr(@PRODUCTTYPE,"Server") Or InStr(@PRODUCTTYPE,"Domain Controller")
Exit
EndIf
$NetMessengerVersion = "5.1.0680" ; Version Cookie. Update this entry if the version changes.
$LocalMessengerVersion = GetFileVersion(%programfiles% + "\Messenger\msmsgs.exe","FileVersion")
Select
Case $Method = 'I'
If $LocalMessengerVersion = $NetMessengerVersion
GetSIP
MessengerDefaults
Exit
; $frmMain.TopMost = 0
$msg = MessageBox("Error: " + @ERROR + " - " + @SERROR,"Notice",48);
; $frmMain.TopMost = 1
EndIf
If $LocalMessengerVersion = ""
$lblStatus.Text = "Please wait, installing Windows Messenger..."
Shell @LSERVER + "\netlogon\kix\tools\Install_Messenger.exe"
GetSIP
MessengerDefaults
Exit
EndIf
If $LocalMessengerVersion < $NetMessengerVersion
$lblStatus.Text = "Please wait, removing Windows Messenger..."
Shell @LSERVER + "\netlogon\kix\tools\Remove_Messenger.exe"
$lblStatus.Text = "Please wait, installing Windows Messenger..."
Shell @LSERVER + "\netlogon\kix\tools\Install_Messenger.exe"
GetSIP
MessengerDefaults
Exit
EndIf
Case $Method = 'U'
If $LocalMessengerVersion > ""
$lblStatus.Text = "Please wait, removing Windows Messenger..."
Shell @LSERVER + "\netlogon\kix\tools\Remove_Messenger.exe"
EndIf
Case 1
;User input not I or U
Exit 1
EndSelect
Exit
EndFunction
GetSIP