Page 1 of 1 1
Topic Options
#146995 - 2005-09-01 08:45 PM AD Query not retreiving results...
dataspike Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
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



Edited by dataspike (2005-09-01 09:08 PM)

Top
#146996 - 2005-09-01 09:34 PM Re: AD Query not retreiving results...
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
If I look at the schema for the User objectClass using Active Directory Attribute Browser, I see that msRTCSIP-PrimaryUserAddress is not present (at least in my domain). Have you verified that this attribute is present for your User objectClass?
Top
#146997 - 2005-09-01 09:38 PM Re: AD Query not retreiving results...
dataspike Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
Quote:

If I look at the schema for the User objectClass using Active Directory Attribute Browser, I see that msRTCSIP-PrimaryUserAddress is not present (at least in my domain). Have you verified that this attribute is present for your User objectClass?




The object is in the domain as I am able to retrieve it with my username. It's created when you install a Live Communication Server. It's for Windows Messenger and other programs.

Any other ideas?

Top
#146998 - 2005-09-01 09:41 PM Re: AD Query not retreiving results...
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Use the browser as suggested to verify that the attribute is registered in your AD schema.

Edited by Chris S. (2005-09-01 09:41 PM)

Top
#146999 - 2005-09-01 09:45 PM Re: AD Query not retreiving results...
dataspike Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
Quote:

Use the browser as suggested to verify that the attribute is registered in your AD schema.




Top
#147000 - 2005-09-01 09:48 PM Re: AD Query not retreiving results...
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
KiX may be barfing on the "-" in the attribute name (not M$'s best decision to put attributes with a dash in them, IMHO). You may want to try wrapping the attribute in quotes...

Code:

$sWhat = "'msRTCSIP-PrimaryUserAddress'"


Top
#147001 - 2005-09-01 09:53 PM Re: AD Query not retreiving results...
dataspike Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
Quote:

KiX may be barfing on the "-" in the attribute name (not M$'s best decision to put attributes with a dash in them, IMHO). You may want to try wrapping the attribute in quotes...

Code:

$sWhat = "'msRTCSIP-PrimaryUserAddress'"






Good idea, but as soon as I do that it craps out on my machine and gives the same error. If I leave it as in the original code, it works fine on my machine, but same error on the other. So, nope...


Edited by dataspike (2005-09-01 09:53 PM)

Top
#147002 - 2005-09-02 10:00 PM Re: AD Query not retreiving results...
dataspike Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
Changed the code... this works or seems to, on all machines.

Code:

Function GetSIP
$objSystemInfo = CreateObject("ADSystemInfo")
$strAuthDistinguishedName = "LDAP://" + $objSystemInfo.UserName
$UserObj = GetObject($strAuthDistinguishedName)
$SIP = $UserObj.Get("msRTCSIP-PrimaryUserAddress")

$msg = MessageBox("Logon Server: " + @LSERVER + @CRLF +
"LDAP Path: " + $strAuthDistinguishedName + @CRLF +
"SIP Address: " + $SIP,"Notice",64)
EndFunction


Top
#195595 - 2009-08-25 08:56 PM Re: AD Query not retreiving results... [Re: dataspike]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
It chokes for me as well on the hyphen
 Quote:


ERROR : unknown command [UserEnabled]!
Script: F:\Logon\BetaGPO.kix
Line : 293


 Code:
	$UPs = GetObject('LDAP://'+$LDAP[0])
		$FirstName	= $UPs.FirstName
		$MiddleName	= $UPs.initials
		$LastName	= $UPs.LastName

		$sCompany 	= $UPs.Company
		$sTitle		= $UPs.Title
		$sMail		= $UPs.mail
		$sDepartment	= $UPs.Department
		$sStreetAddress	= $UPs.StreetAddress
		$sCity		= $UPs.L
		$sState		= $UPs.St
		$sPostalCode	= $UPs.PostalCode
		$sCountry	= $UPs.Co
		$sPhoneNumber	= $UPs.telephoneNumber
		$sFaxNumber	= $UPs.FacsimileTelephoneNumber
		$sCellNumber	= $UPs.Mobile
		$sWebPage	= $UPs.wWWHomePage
		$sSIPEnabled	= $UPs.msRTCSIP-UserEnabled
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 581 anonymous users online.
Newest Members
Audio, Hoschi, Comet, rrosell, PatrickPinto
17880 Registered Users

Generated in 0.059 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org