Jump to content
BigDaddyO

ObjEvent Handling with same Func from Multiple Objects

Recommended Posts

Some background on what I'm doing.
I'm trying to build a version of the Citrix ControlUp Logon Simulator in order to perform multiple logins with different accounts from the same system so I can run some automated tests.
The existing ControlUp free app doesn't do exactly what I wanted, and since it was free, I figured it must not have been difficult so I looked into it and found the Citrix ICAClient API's.
It seems like my script will work, but I have to sit down with my Citrix guys to figure out the proper connection address as I'm connecting, but it's disconnecting shortly after.

Now for my question.
Each connection will need it's own ObjCreate() and ObjEvent() since they are using different credentials.
There are 35 events that I need to watch for each ObjCreate() to know what the sessions are doing.

Is there a way to know what Object is initiating the event so I know which Session just did what?
Right now, the only thing I can think of is to hard code the 35 event functions 20+ times, or to launch my script 20+ times each with a different account.

 

below is my POC code and a small sample of the Event functions.

Global $aUsers[20][3]   ;[][0] = username, [][1] = password, [][2] = citrixIP, [][3] = publishedDesktop/App
Global $oICA[20][2] ;Create an array to store the connected object and Events for each user we will be connecting with

;Move through each user and connect to the specified Citrix box
For $u = 0 to UBound($aUsers) - 1

    $oICA[$u][0] = ObjCreate("Citrix.ICAClient")
    If @error Then
        ConsoleWrite("Failed to connect to ICA" & @CRLF)
        Exit
    Else
        ConsoleWrite("Sucessfully connected to ICS" & @CRLF)
    EndIf


;Each of the ICA objects will need their own event functions?!?
    $oICA[$u][1] = ObjEvent($oICA[$u][0], "ICO_")   ;Register all of the events that can be returned.  Add them as Func ICO_eventname()
    If @error Then ConsoleWrite("Failed to trap com events" & @CRLF)

    ;Cant easily use the Events with the loop, so simply query waiting for the connected or disconnected, and the OnWindowDisplayed() > 0

    With $oICA[$u][0]

    ;These will set the Display settings within the connected desktop
        .DesiredColor = 8   ;Default = 1 which is 16 color which should be fine if not checking for colors, 4 = 16bit, 8 = 24bit, 16 = 32bit
        .DesiredHRes = 1024
        .DesiredVRes = 768

    ;These will set how that connected desktop will be displayed within the connection
        .ScalingMode = 2
        .ScalingWidth = 640
        .ScalingHeight = 480

        .Username = $aUsers[$u][0]
        .SetProp("ClearPassword", $aUsers[$u][1])   ;Apparently in .ica %temp% folder while connected I can grab the encrypted password to store in db, but would be manual process
        .Domain = @LogonDomain
        .Address = $aUsers[$u][2]           ;Starts, but seems to be refused as it closes shortly after opening
        .InitialProgram = $aUsers[$u][3]        ;What Published app/Desktop we want to launch on that server
        .Launch = True                  ;Open the Citrix application window instead of trying to embed in my own app.
        .Connect()                  ;Connect to the specified Citrix server/application/ICA...

    EndWith

Next

;Loop waiting for events to occur
$hTimer = TimerInit()
While 1
    sleep(100)
WEnd


;Do I really need to duplicate all of these 20+ times IC0_ > IC19_?  or is there some way to know which Object called the event?
Func ICO_OnConnect()
    ConsoleWrite("OnConnect() was triggered" & @CRLF)
EndFunc

Func ICO_OnConnectFailed()
    ConsoleWrite("OnConnectFailed() was triggered" & @CRLF)
    ConsoleWrite("OnConnectFailed Error = " & $oICA.GetErrorMessage($oICA.GetLastError) & @CRLF)
    ConsoleWrite("OnConnectFailed Client_Error = " & $oICA.GetErrorMessage($oICA.GetLastClientError) & @CRLF)
    Exit
EndFunc

Func ICO_OnConnecting()
    ConsoleWrite("OnConnecting() was triggered" & @CRLF)
EndFunc

Func ICO_OnDisconnect()
    ConsoleWrite("OnDisconnect() was triggered" & @CRLF)
    ConsoleWrite("OnDisconnect Error = " & $oICA.GetErrorMessage($oICA.GetLastError) & @CRLF)
    ConsoleWrite("OnDisconnect Client_Error = " & $oICA.GetErrorMessage($oICA.GetLastClientError) & @CRLF)
    Exit    ;Exit the script since we have been disconnected for some reason.  Assuming a refused connection
EndFunc

 

Thanks for any pointers you can offer.


hmm... I guess I have to have a signature...

Share this post


Link to post
Share on other sites

Have a look at macro @COM_EventObj


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (NEW 2019-07-13 - Version 0.5.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

:) 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (NEW 2019-07-13 - Version 0.5.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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

×
×
  • Create New...