Page 1 of 2 12>
Topic Options
#172354 - 2007-01-04 04:48 AM IDispatch Pointers not allowed in expressions
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
Having a problem getting a script to work when using an Array to feed information to a Function.
I have modified Alex Heitz's ADSearch() function to get specific information.

The first script works fine, but the second one gives me the IDispatch Pointers error.

homemdb is an AD attribute indicating the user's Exchange mailstore. I am
trying to get the homemdb and a partial on the servername where the
homemdb is located.

What am I doing wrong?

***********************************************

;1st script - this one works, but it is not practical for hundreds of names
Code:
break ON
$test1="abernade"
$test2="dbullock"

$str=""
$server=""
adsearch($test1)
? $str
? $server

$str=""
$server=""
adsearch($test2)
? $str
? $server

Function ADSearch($ADAccountName)
Dim $AdoCon
dim $AdoCommand
dim $Recordset
dim $Filter
dim $homemdb
dim $store
if len($ADAccountName)>0 
      $filter=" where samAccountName='"+$ADAccountName+"' "
      $AdoCon = CreateObject("ADODB.Connection")
      $AdoCon.Provider = "ADsDSOObject"
      ; Current credentials are used, as username and password aren't specified
      $AdoCon.Open("Active Directory Provider")
      ; Create ADO command object for the connection.
      $AdoCommand = CreateObject("ADODB.Command")
      $AdoCommand.ActiveConnection = $AdoCon
      $AdoCommand.CommandText ="Select homemdb from 'LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")+"' "+$filter
      ; Execute the query.
      $Recordset = $AdoCommand.Execute
      $homeMDB=split($recordset.fields("homemdb"),",")  ;This is the line where I get the IDispatch Pointers error
      $store=split($homemdb[0],"=")
      $str=$store[1]
      $server=right($homemdb[3],4)
Else
      Exit
endif
Endfunction
 

************************************************************

;2nd script - this one fails
Code:
break ON
dim $test[5]
$test[1]="abernade" ;I don't normally create arrays this way, but for simplicity
$test[2]="dbullock"

for $x=1 to 2
   $str=""
   $server=""
   adsearch($test[$x])
   ? $str
   ? $server
next

Function ADSearch($ADAccountName)
Dim $AdoCon
dim $AdoCommand
dim $Recordset
dim $Filter
dim $homemdb
dim $store
if len($ADAccountName)>0 
      $filter=" where samAccountName='"+$ADAccountName+"' "
      $AdoCon = CreateObject("ADODB.Connection")
      $AdoCon.Provider = "ADsDSOObject"
      ; Current credentials are used, as username and password aren't specified
      $AdoCon.Open("Active Directory Provider")
      ; Create ADO command object for the connection.
      $AdoCommand = CreateObject("ADODB.Command")
      $AdoCommand.ActiveConnection = $AdoCon
      $AdoCommand.CommandText ="Select  homemdb from 'LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")+"' "+$filter
      ; Execute the query.
      $Recordset = $AdoCommand.Execute
      $homeMDB=split($recordset.fields("homemdb"),",")  ;This is the line where I get the IDispatch Pointers error
      $store=split($homemdb[0],"=")
      $str=$store[1]
      $server=right($homemdb[3],4)
Else
      Exit
endif
Endfunction
 


Thanks for you assistance,
Dale


Edited by Daleco (2007-01-09 05:44 AM)
_________________________
Dale

Top
#172356 - 2007-01-04 07:26 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
First I'd like to suggest you edit your post and put your code in the code tags (# button) so that it will be easier to read.

The other odd thing I see is it looks like you've modified the UDF to pull different information, but its not returning anything, ie the ADSearch variable is not being defined with a return value.

As for your error, You might try changing this:
   $homeMDB=split($recordset.fields("homemdb"),",")
to (untested)
   $homeMDB=$recordset.fields("homemdb")
   $homeMDB=split($homeMDB,",")

Also, your for loop could be much easier...
$test="abernade","dbullock"
for each $x in $test
   ? $x
   ;do stuff
next


Top
#172357 - 2007-01-04 07:31 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Hello Daleco and welcome to the board.

Please review this thread to further enhance your participation here on the board.


The Post/Reply Formatting Box and How to use it
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=171901


Thanks


.

Top
#172358 - 2007-01-04 07:48 AM Re: Dispatch Pointers not allowed in expressions [Re: Allen]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
Thanks Allen

By using the loop as you indicated it seems to work. It seems in this case that you can't use the array directly in the Function call as I did in the 2nd script. I did not have to change the homemdb line. This script will be used to capture information on up to several hundred accounts using the account name. Wioth a couple more tweeks this should work nicely in the main script I'm using.

Hopefully I will not run into any more difficulty with it.
_________________________
Dale

Top
#175255 - 2007-04-06 06:09 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
I am still having difficulty with this piece of code. I have found that the function ADSearch() does not work well if the account name has a period in it, I get the IDispatch error. If the account name does not have a period in it the script below runs fine. The ADSearch function is modified slightly because I needed a different field returned.

 Code:
break ON
$test1="aber.nade" ; The period in this account name causes the IDispatch error

$str=""
$server=""
adsearch($test1)
? $str
? $server

Function ADSearch($ADAccountName)
Dim $AdoCon
dim $AdoCommand
dim $Recordset
dim $Filter
dim $homemdb
dim $store
if len($ADAccountName)>0 
      $filter=" where samAccountName='"+$ADAccountName+"' "
      $AdoCon = CreateObject("ADODB.Connection")
      $AdoCon.Provider = "ADsDSOObject"
      ; Current credentials are used, as username and password aren't specified
      $AdoCon.Open("Active Directory Provider")
      ; Create ADO command object for the connection.
      $AdoCommand = CreateObject("ADODB.Command")
      $AdoCommand.ActiveConnection = $AdoCon
      $AdoCommand.CommandText ="Select homemdb from 
'LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")+"' "+$filter
      ; Execute the query.
      $Recordset = $AdoCommand.Execute
      $homeMDB=split($recordset.fields("homemdb"),",")  ; This gives the error
      $store=split($homemdb[0],"=")
      $str=$store[1]
      $server=right($homemdb[3],4)
Else
      Exit
endif
Endfunction


Edited by Daleco (2007-04-06 07:28 AM)
_________________________
Dale

Top
#175256 - 2007-04-06 07:09 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Maybe you can start in debug mode (/d) and step through each line to see which line gives the error.
Top
#175257 - 2007-04-06 07:28 AM Re: Dispatch Pointers not allowed in expressions [Re: Witto]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
I marked the line in the code where the error occurs.
_________________________
Dale

Top
#175258 - 2007-04-06 01:12 PM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
It is this part:
 Code:
$recordset.fields("homemdb") ; This gives the error

That you cannot split
 Code:
Split($recordset.fields("homemdb"),",") ; This gives the error

You can put it in a variable
 Code:
Dim $Var
$Var = $recordset.fields("homemdb")


Top
#175273 - 2007-04-07 02:21 AM Re: Dispatch Pointers not allowed in expressions [Re: Witto]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
Thanks for that Witto, but the problem still remains.

If I use the account name "aber.nade" it does not work, but if the account name does not contain a period "abernade" then it works fine. The problem seems to center around the period in the account name.
_________________________
Dale

Top
#175274 - 2007-04-07 03:46 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Not that this has anything to do with the error you are receiving, but I think you need to start by getting your code correct(as I noted earlier in this thread). The way you are using the UDF is not right. There is a FAQ on using and creating UDFs: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=82017&page=1#Post82017

Please consider the following changes: (I could not test this so its very possible there are bugs)

break ON
$=setoption("Explicit","on")
$=setoption("NoVarsinstrings","on")
dim $test1, $server, $store


$test1="aber.nade" ; The period in this account name causes the IDispatch error


$Server=HOMEMDB($test1,"Server")
$Store=HOMEMDB($test1,"Store")
? $store
? $server


Function HOMEMDB($ADAccountName,$mode)
Dim $AdoCon
dim $AdoCommand
dim $Recordset
dim $Filter
dim $homemdb
dim $store
if len($ADAccountName)>0
$filter=" where samAccountName='"+$ADAccountName+"' "
$AdoCon = CreateObject("ADODB.Connection")
$AdoCon.Provider = "ADsDSOObject"
; Current credentials are used, as username and password aren't specified
$AdoCon.Open("Active Directory Provider")
; Create ADO command object for the connection.
$AdoCommand = CreateObject("ADODB.Command")
$AdoCommand.ActiveConnection = $AdoCon
$AdoCommand.CommandText ="Select homemdb from 'LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")+"' "+$filter
; Execute the query.
$Recordset = $AdoCommand.Execute
$homeMDB=split($recordset.fields("homemdb"),",") ; This gives the error
select
case $mode="Store"
$store=split($homemdb[0],"=")
$HOMEMDB=$store[1]
case $mode="Server"
$HOMEMDB=right($homemdb[3],4)
endselect
endif
Endfunction


Please read the faq and look through/test my example. If you don't understand why I did it this way then please ask.

If we can get this correct, we might be able to figure out the other problem as well.

Top
#175275 - 2007-04-07 05:28 AM Re: Dispatch Pointers not allowed in expressions [Re: Allen]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
Allen,
Thanks for the test script. I had made the changes you suggested before, but I have the same results when the logon name has a period in it. This is part of what is in the HomeMDB record:

CN=PAFB-SG7-AEN
CN=PAFB-SG7 (T-Z)
CN=InformationStore
CN=serverML30
CN=Servers
CN=First Administrative Group
CN=Administrative Groups
CN=AFSPC
CN=Microsoft Exchange
CN=Services
CN=Configuration

The parts I am capturing are in RED bold. I have written this script several different ways and the results are always the same, as long as there is no period in the account name it runs fine.

The test script you wrote also runs fine if there is no period in the account name, but fails if there is one.

Your script gets the IDispatch error on the same line as I do.
 Code:
       $homeMDB=split($recordset.fields("homemdb"),",")  ; This gives the IDispatch error
_________________________
Dale

Top
#175276 - 2007-04-07 05:35 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Okay... if it works but is broke with the periods.. that is good.

Can you provide the same info for a user with a period in the name as you did above (the red)?

Top
#175277 - 2007-04-07 05:40 AM Re: Dispatch Pointers not allowed in expressions [Re: Allen]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
It does not process for a user with the period in it. The information above is from a user with no period. BTW, your script does not fail if there is not period in the name, but is doesn't return the data I need either. The data will be different for many users and I need both pieces of information for each user.
_________________________
Dale

Top
#175278 - 2007-04-07 05:46 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I changed the way the values are loaded... did you try the script exactly as it is?

Do you MSN?

Top
#175279 - 2007-04-07 05:51 AM Re: Dispatch Pointers not allowed in expressions [Re: Allen]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
MSN? I don't understand this.

I ran your script exactly as you provided, except to remove the period or put it in. With the period in it fails with the IDispatch.

The $store and $Server are empty.
_________________________
Dale

Top
#175280 - 2007-04-07 05:55 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I understand that it did not fix the error... what I am confused about is why it did not return any values. Can you add some error checking to the function?

MSN Messenger is what I meant to say.

Top
#175281 - 2007-04-07 06:11 AM Re: Dispatch Pointers not allowed in expressions [Re: Allen]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
No I can't use MSN (not allowed here)

Without a period in the account name:
The $Homemdb is populated correctly in each instance below

 Code:
       $homeMDB=split($recordset.fields("homemdb"),",")  
       select
          case $mode="Store"
            $store=split($homemdb[0],"=")
            $HOMEMDB=$store[1]
          case $mode="Server"
            $HOMEMDB=right($homemdb[3],4)
       endselect


With a period in it fails on the first line above. Do you have a suggestion on a way to error check this?
_________________________
Dale

Top
#175282 - 2007-04-07 06:39 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I may need some help from some of the COM gurus but try this and see if it says anything with and with out the period



right after
$Recordset = $AdoCommand.Execute
add
? "_______________________"
? $recordset.recordcount
? "_______________________"
?

Top
#175283 - 2007-04-07 06:44 AM Re: Dispatch Pointers not allowed in expressions [Re: Allen]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
With a period:
_______________________
0
_______________________


Without a period:
_______________________
1
_______________________
_________________________
Dale

Top
#175284 - 2007-04-07 06:47 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
k... so that means that with a period it is not running the query correctly. The reason you are getting an error is because its trying to split something that has nothing there.

Now to figure out why...

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.081 seconds in which 0.048 seconds were spent on a total of 14 queries. Zlib compression enabled.

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