Sign in to follow this  
Followers 0
roman

Problem with Citrix COM object

16 posts in this topic

#1 ·  Posted (edited)

Hi

I have a Citrix COM object which provides the following methodes:

PS  $lm|get-member

   TypeName: System.__ComObject#{29d9c0a3-5d2b-44b3-8ad9-0545be9ec17e}
Name                 MemberType Definition
----                 ---------- ----------
AttachLoadEvaluator  Method  void AttachLoadEvaluator (uint64, uint64, SA...
GetLMDisabledServers Method  SAFEARRAY(string) GetLMDisabledServers (string)
QueryServers         Method  SAFEARRAY(byte) QueryServers (uint64)
SetServerLMState     Method  void SetServerLMState (string, int)

With this PowerShell commands, i get the disired server name, in this case server "XXXXXXX181":

PS > $lm = New-Object -COM CPSCOMInterop.CPSLoadManager.1
PS > $srv=$lm.GetLMDisabledServers("XENAPP")
PS > $srv
XXXXXXX181

If i try to script that with AutoIt, i get a variable ($var) which content i can not use / or which has no content? $var contains no string, it is no array, i get no array dimensions and it is no object...?

$o_LM = ObjCreate("CPSCOMInterop.CPSLoadManager.1")
$var = $o_LM.GetLMDisabledServers("XENAPP")

Sorry, i'm not very familar with COM. May be somebody has any hints for an "COM beginner"?

Thanks and kind regards,

Roman.

Edited by roman

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

First thing when working with COM objects is to implement a COM error handler.

So I would expand your script like:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler
$o_LM = ObjCreate("CPSCOMInterop.CPSLoadManager.1")
If @error <> 0 or Not IsObj($o_LM) Then Exit MsgBox(16, "Error", "Could not create object!")
$var = $o_LM.GetLMDisabledServers("XENAPP")
If @error <> 0 or Not IsObj($o_LM) Then Exit MsgBox(16, "Error", "Could not get Server!")
Exit

; This is my custom defined error handler
Func MyErrFunc()

  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"    & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )

Endfunc
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler
$o_LM = ObjCreate("CPSCOMInterop.CPSLoadManager.1")
If @error <> 0 or Not IsObj($o_LM) Then Exit MsgBox(16, "Error", "Could not create object!")
$var= $o_LM.GetLMDisabledServers("XENAPP")
If @error <> 0 or Not IsObj($var) Then Exit MsgBox(16, "Error", "Could not get Server!")
Exit
; This is my custom defined error handler
Func MyErrFunc()
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"  & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "     & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "     & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile   & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
Endfunc

Thank You for your replay

In line 5 it should be "$var" shouldn't it?

No COM error occurs! There ist not an error but $var is not an object.

Therefore the message "Could not get Server!" appears.

Do you have any other tips?

Thank you in advance Roman

Edited by roman

Share this post


Link to post
Share on other sites

Line 5? Right, should be $var.

The method name is GetLMDisabledServers so maybe it returns an array?

You could try:

#include <array.au3>
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler
$o_LM = ObjCreate("CPSCOMInterop.CPSLoadManager.1")
If @error <> 0 or Not IsObj($o_LM) Then Exit MsgBox(16, "Error", "Could not create object!")
$var= $o_LM.GetLMDisabledServers("XENAPP")
If @error <> 0 or Not IsObj($var) Then Exit MsgBox(16, "Error", "Could not get Server!")
If IsArray($var) Then
    _ArrayDisplay($var)
Else
    MsgBox(16, "Info", "Datatype of $var is: " & VarGetType($var))
Endif
Exit
; This is my custom defined error handler
Func MyErrFunc()
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"  & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "   & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "   & @TAB & $oMyError.source     & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile   & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
Endfunc

If it is an array the array is displayed. If not the datatype of $var is displayed.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Sorry, bat it doesn't work anyway. It seems to be an array as you can see from the Powershell get-member Command. It seems to be a SAFEARRAY. What ever a SAFEARRAY is.

#include <array.au3>
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler
$o_LM = ObjCreate("CPSCOMInterop.CPSLoadManager.1")
If @error <> 0 or Not IsObj($o_LM) Then Exit MsgBox(16, "Error", "Could not create object!")
$var= $o_LM.GetLMDisabledServers("XENAPP")
If @error <> 0 or Not IsObj($var) Then MsgBox(16, "Error", "Could not get Server!")
If IsArray($var) Then
MsgBox(0,"","")
    _ArrayDisplay($var)
Else
    MsgBox(16, "Info", "Datatype of $var is: " & VarGetType($var))
Endif
Exit
; This is my custom defined error handler
Func MyErrFunc()
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"  & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "   & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "   & @TAB & $oMyError.source   & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile   & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
Endfunc

We get the result from if isarray with an error:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Temp\citrix.au3"

C:\Program Files\AutoIt3\Include\array.au3 (371) : ==> Array variable subscript badly formatted.:

Local $avArrayText[$iUBound + 1]

Local $avArrayText[^ ERROR

>Exit code: 1 Time: 4.593

If i remark Line 7 to 10 and line 12 I get the answer "Datatype of $var is: Array

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Then we should first gather some info about the array.

If IsArray($var) Then
  MsgBox(16, "Info", "Dimensions: " & UBound($var, 0))
  If UBound($var, 0) >= 1 then MsgBox(16, "Info", "Elements in 1st dimension: " & UBound($var, 1))
  If UBound($var, 0) > 1 then MsgBox(16, "Info", "Elements in 2nd dimension: " & UBound($var, 2))
EndIf
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Dimensions: 1

Elements in 1st dimensin: 0

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

So the method returned a valid result: a 1-dimensional array with no entries.

What do you get if you just call:

$var= $o_LM.GetLMDisabledServers()
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

COM Error!

Invalid number of parameters

8002000E

Line 5

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Ok, then try

$var= $o_LM.GetLMDisabledServers("")

BTW:

Do you know what parameters the method requires? Just one or could there be more? Of what type should the parameters be string, array?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

the same behavior!

I know that the method requires a string (only one!) and thap "XENAPP" is the right string (as you can see from the powershell commands)

Share this post


Link to post
Share on other sites

You are sure it's a string? Do you have a documentation of the COM interface? Sometimes methods require to pass an array.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I'm sure it is a string:

GetLMDisabledServers Method SAFEARRAY(string) GetLMDisabledServers (string)

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Savearray seems to be a C++ thing (according to google). Maybe AutoIt can't handle this kind of datatype or has to handle it different.

I don't write C++ so maybe some of the C++ gurus here knows how to access the result?

SaveArrays

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hier noch eine gute Beschreibung von SaveArrays auf deutsch. (A good description of what Savearrays are written in german)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

The only problem I see here is SAFEARRAY(string)? What's that?

AutoIt understands plenty of COM types, but apparently not this one. I can add another which I think this one could be, but it would be better if the real type could be confirmed first.

@roman, send me PM and I will tell you what to do if you want.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0