#85866 - 2002-06-02 07:45 AM
GetInfoEx COM Bug? (Help with GetInfoEX)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I was translating my Perl LookupMailboxesFromAccount.exe to KiXtart and have run into a problem with GetInfoEX. I can not seem to to pass the proper data type to the function. See the somewhat working code below. I need to use GetInfoEx to obtain the "Home-MDB" property that is the actual server location of a mailbox.
You will see the problem line in GetMailBoxProperties($AdsPath) below. code:
$ExchangeServer="YourServer" $Domain="YourDomain" $Account="YourAccount"
$Mailboxes = ADOQueryAssocNTAccount($ExchangeServer, LookupHexSid($Domain, $Account))
? "Mailboxes for " + $Domain + "\" + $Account ? "------------------------------------------------------------------" for each $mailbox in $MailBoxes GetMailBoxProperties($Mailbox) ? "------------------------------------------------------------------" next
Function LookupHexSid($Domain, $Account) Dim $ADsPath, $ADsSid $ADsPath = "WinNT://" + $Domain + "/" + $Account $ADsSid = createobject("ADsSid") $ADsSid.setas(5,$ADsPath) $LookupHexSid = $ADsSid.getas(1) EndFunction
Function ADOQueryAssocNTAccount($ExchangeServer, $HexSid) Dim $ADOconn, $ADOQueryString, $objRS, $A, $i $ADOconn = CreateObject("ADODB.Connection") $ADOConn.Provider = "ADSDSOObject" $ADOConn.Open() if @ERROR exit @ERROR endif $ADOQueryString = "<LDAP://$ExchangeServer>;(&(objectClass=person)(Assoc-NT-Account=$HEXsid));adspath;subtree"; $objRS = $ADOconn.Execute($ADOQueryString) if VarType( $objRS ) <> 0 $i=0 Do ReDim Preserve $A[$i] ;? $objRS.Fields("adspath").value $A[$i] = $objRS.Fields("adspath").value $objRS.movenext $i=$i+1 until $objRS.EOF $ADOQueryAssocNTAccount=$A else ? "No MailBoxes found!" endif exit 0; EndFunction
Function GetMailBoxProperties($AdsPath) Dim $objMailBox Dim $A[1] $objMailBox = GetObject($ADsPath) ? "Display Name: " $objMailBox.get("cn") ? " Given Name: " $objMailBox.get("givenname") ? " Last Name: " $objMailBox.get("sn") ? " Alias: " $objMailBox.get("uid") ? "Primary SMTP: " $objMailBox.get("mail") ? " RDN: " $objMailBox.get("rdn") ? " Home MTA: " $objMailBox.get("home-mta")
; Help Please ; How does pass the required array to GetInfoEdx ??? $objMailBox.GetInfoEx("home-mdb", 0); ? "Using Text: @error @serror" $A = "home-mdb","" $objMailBox.GetInfoEx($A, 0); ? "Using Array: @error @serror" ? " Home MDB: " $objMailBox.get("home-mdb")
? ;? "Other Mailboxes:" ;$array=$objMailBox.get("othermailbox") ;for each $item in $array ; $type=substr($item,1,instr($item,"$$")-1) ; $address=substr($item,len($type)+2,len($item)) ; ? " " $type ": "$address ;next
EndFunction
[ 03 June 2002, 22:07: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#85868 - 2002-06-02 07:05 PM
Re: GetInfoEx COM Bug? (Help with GetInfoEX)
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
|
|
Top
|
|
|
|
#85869 - 2002-06-02 10:00 PM
Re: GetInfoEx COM Bug? (Help with GetInfoEX)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Shawn,
This is all that @error and @serror return. I make two attempts in my code as posted. The first with text and the second with a Kix array.
Using Text: 1 COM exception error "GetInfoEx" (Active Directory - Unspecified error ) [1/1] Using Array: 1 COM exception error "GetInfoEx" ((null) - (null)) [1/1] Home MDB:
This is what VB uses: x.GetInfoEx Array("givenName", "sn"), 0
I can this easily in Perl as: $objMailbox->GetInfoEx(["Home-MDB"], 0);
But KiXtart just doesn't seem to work. [ 02 June 2002, 22:04: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#85871 - 2002-06-02 11:28 PM
Re: GetInfoEx COM Bug? (Help with GetInfoEX)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Same result using: $A="home-mdb","sn"
|
|
Top
|
|
|
|
#85872 - 2002-06-03 03:30 PM
Re: GetInfoEx COM Bug? (Help with GetInfoEX)
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Could this have to do with the whole (support or lack of support for the) multidimensional array issue?
Brian
|
|
Top
|
|
|
|
#85873 - 2002-06-03 03:40 PM
Re: GetInfoEx COM Bug? (Help with GetInfoEX)
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
I'm trying to play catch-up here. BTW, thanks Howard for looking at this.
As a side-note to anyone trying this from home, or probably more appopriate, from work... This does require the ADsSecurity.dll in order to associate the NT account with a SID.
Does the GetInfoEx have anything to do with this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netdir/ad/optimization_using_getinfoex.asp
|
|
Top
|
|
|
|
#85874 - 2002-06-03 03:57 PM
Re: GetInfoEx COM Bug? (Help with GetInfoEX)
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Chris, Howard, et al:
I was looking at this snippet of code that Chris pointed to, whats up with this, it assigns an array, then assigns a variable to point to the array (which using vbs, i thought would have been the same thing) ? :
' Initialize the array of properties to pass to GetInfoEx PropArray = Array("description", "distinguishedName") ' Make the array a single variant for passing to GetInfoEx Prop = PropArray
Might want to give it a try Howard but not holding my breath
-Shawn
|
|
Top
|
|
|
|
#85875 - 2002-06-03 03:59 PM
Re: GetInfoEx COM Bug? (Help with GetInfoEX)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I have to use GetInfoEx because the property "Home-MDB" is not in the property cache by default. The problem here seems to be that KiXtart can not passed the array data type that GetInfoEx needs. Maybe the KiXtart syntax for the COM call needs to be altered or Ruud may need to look at this particular COM usage.
|
|
Top
|
|
|
|
#85876 - 2002-06-03 04:09 PM
Re: GetInfoEx COM Bug? (Help with GetInfoEX)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Shawn, the statement $A = Array("z","x") naturely causes a script error.
$A = "z","x" $B = $A then to GetInfoEx also fails.
|
|
Top
|
|
|
|
#85878 - 2002-06-03 04:21 PM
Re: GetInfoEx COM Bug? (Help with GetInfoEX)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
When using sealeopard's suggestion the following is generated:
1 COM exception error "GetInfoEx" (Active Directory - The Active Directory datatype cannot be converted to/from a native DS datatype
This is for
using $A directly and for using $B where $B=$A. [ 03 June 2002, 16:22: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#85880 - 2002-06-03 06:35 PM
Re: GetInfoEx COM Bug? (Help with GetInfoEX)
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Howard, it also seems that the "No Mailboxes Found" part of your ADOQueryAssocNTAccount function isn't working properly. If I query an NT account without a mailbox it still runs the GetMailBoxProperties function. This returns a "Script Error : unknown command !" error.
I think if you check the value of the property for a nul value you can get around this (in the GetMailBoxProperties function):
code:
if $objMailBox.get("rdn") <> "" ? "You have a mailbox" else ? "You don't have a mailbox" endif
|
|
Top
|
|
|
|
#85881 - 2002-06-03 07:55 PM
Re: GetInfoEx COM Bug? (Help with GetInfoEX)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Shawn, already tried that one. I think this is either a strong deficiency or bug in KixTart COM.
Chris, it was working in a previous version before I used functions. I will fix it before it is published as "Working Code"
|
|
Top
|
|
|
|
#85883 - 2002-06-03 10:03 PM
Re: GetInfoEx COM Bug? (Help with GetInfoEX)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Shawn, the array problem has never worked. I was referring to Chris' comment about the "Mailbox not found!" not working properly.
The script run under RC2 yields: Using Text: -2147352567 Exception occurred. Using Array: -2147352567 Exception occurred.
The true issue appears to be that in VB or VBscript one can use the "Array" function to pass data to GetInfoEx but in Kixtart the arrays are passed the same way or are not contructed in a way that COM recognizes.
I really do not know where the GetInfoEx method can be used generically. I think that this code is quite easily spared down to something that can be used in reproducing the problem. It think that we could just ask Ruud to effectively transalate the working VB script found on MSDN that uses GetInfoEx. If he can not because of this issue, then the bug? is reproduced.
code:
Dim PropArray As Variant Dim Prop As Variant Dim DescList As Variant Dim obj As IADs Set obj = GetObject("LDAP://MyMachine") ' Initialize the array of properties to pass to GetInfoEx PropArray = Array("description", "distinguishedName") ' Make the array a single variant for passing to GetInfoEx Prop = PropArray ' Get just the description and DN properties obj.GetInfoEx Prop, 0 DescList = obj.Get("description") ' Enumerate the descriptions For Each Desc In DescList ' Print the descriptions Deubg.Print (Desc) Next
OR code:
Dim x As IADs Set x = GetObject("LDAP://CN=JSmith,CN=Users,DC=Fabrikam,DC=com") 'Retrieve givenName and sn from the underlying directory storage. 'Cache should have givenName and sn values. x.GetInfoEx Array("givenName", "sn"), 0 Debug.Print x.Get("givenName") ' Property is in the cache Debug.Print x.Get("sn") ' Property is in the cache 'If the "homePhone" property is not in the cache (in the next line), 'GetInfo will be called implicitly. Debug.Print x.Get("homePhone")
|
|
Top
|
|
|
|
#85885 - 2002-06-05 02:06 PM
Re: GetInfoEx COM Bug? (Help with GetInfoEX)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Thanks Ruud, but I am still some confused by your use of "homemdb" and not "home-mdb" as in http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ds2x/hh/ ds2x/exds_ds2exchgd_2j3s.asp
Is this a different attribute? I use the "Home-MDB" attribute in Perl and it is documented in the URL above.
code:
Dim objMailbox As IADs Dim objStore As IADs
Set objMailbox = _ GetObject("LDAP://Server/cn=Mailbox,cn=Recipients,ou=Site,o=Org")
objMailbox.GetInfoEx Array("Home-MDB"), 0 Debug.Print objMailbox.Get("Home-MDB")
'This distinguished name can be parsed out to obtain the server name. ' Or you can bind to the Home-MDB Path and get the parent object StorePath = objMailbox.Get("Home-MDB") Set objStore = GetObject("LDAP://Server/" & StorePath) Debug.Print objStore.Parent
Set objMailbox = Nothing Set objStore = Nothing
[ 05 June 2002, 14:09: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 400 anonymous users online.
|
|
|