Jump to content

ControlGetText Problems


Recommended Posts

I've spent two days wrestling with this pouring over posts in this forum and the help file. I can't find anything that accounts for the behavior of ControlGetText. I use multiple VPNs and they use different Proxies, of course. I'm trying to determine if the VPN for one of the networks is in session so that I can automate the proxy settings to that network. The VPN client is F5 BIG-IP Edge Client and it has a static control right on the dialog that says whether it is "Connected" or "Disconnected". I'm trying to use ControlGetText to read that static control and get the text. The Au3Info for the control is as follows:

>>>> Window <<<<

Title: BIG-IP Edge Client™

Class: #32770

Position: 932, 254

Size: 561, 270

Style: 0x14CA00C4

ExStyle: 0x00010101

Handle: 0x00000000000304A2

>>>> Control <<<<

Class: Static

Instance: 1

ClassnameNN: Static1

Name:

Advanced (Class): [CLASS:Static; INSTANCE:1]

ID: 2040

Text: Disconnected

Position: 76, 17

Size: 323, 28

ControlClick Coords: 29, 17

Style: 0x5002C08D

ExStyle: 0x00000024

Handle: 0x000000000007052E

>>>> Mouse <<<<

Position: 1040, 313

Cursor ID: 0

Color: 0x5C6977

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<

Connection

Auto-Connect

Connect

Disconnect

Change Server

Show Graph

View Details

Disconnected

Server: XXXXXXXXXXXXXX

Close a connection and disconnect.

Outbound Traffic

0 b/s

Inbound Traffic

0 b/s

>>>> Hidden Text <<<<

Traffic

1 minute ago

30 seconds ago

Current

Inbound: 0 B total (0% compression)

Throughput: 0 b/s

Outbound: 0 B total (0% compression)

Throughput: 0 b/s

Notifications

I have X'd out the server name as that is all that is in any way identifiable in this information. It is not involved in the problem.

The code that I'm using is as follows:


                             MsgBox( 0, "VPN Sess Detect", $DetectVPNSessionType)
                                MsgBox( 0, "Does Process Exist?", $VPNProcessName)
                                If ProcessExists( $VPNProcessName ) Then
                                    MsgBox( 0, "Process Exists", $VPNProcessName)
                                    MsgBox( 0, "Does Window Exist?", $VPNWindowTitle)
                                    If WinExists($VPNWindowTitle) Then
                                        MsgBox( 0, "Window Exists", $VPNWindowTitle)
                                        $VPNWindowTitle = WinGetTitle($VPNWindowTitle)
                                        Opt( "WinTitleMatchMode", 3)
                                        $VPNWindowText = WinGetText($VPNWindowTitle, "")
                                        MsgBox( 0, "Full Window Title", $VPNWindowTitle)
                                        MsgBox( 0, "VPN Window Text", $VPNWindowText)
                                        If StringInStr(ControlGetText($VPNWindowTitle, "", $VPNControlID), $VPNSessionText) > 0 Then
                                            MsgBox( 0, "VPN Session Exists", $VPNControlID & "/" & $VPNSessionText)
                                            MsgBox( 0, "VPN Session Detect Result", ControlGetText($VPNWindowTitle, "", $VPNControlID))
                                            MsgBox( 0, "VPN Session Detect Result", ControlGetText($VPNWindowTitle, "", "[CLASS:Static; INSTANCE:1]"))
                                     Else
                                            MsgBox( 0, "VPN Session Does Not Exist", $VPNControlID & "/" & $VPNSessionText)
                                            MsgBox( 0, "VPN Session Detect Result", ControlGetText($VPNWindowTitle, "", $VPNControlID))
                                            MsgBox( 0, "VPN Session Detect Result", ControlGetText($VPNWindowTitle, "", "[CLASS:Static; INSTANCE:1]"))
                                        EndIf

[code=auto:0]

ControlGetText against the Static1 control which should be either "Connected or Disconnected" returns "Activation" or "Loading" and these values have nothing to do with the state of the VPN so I can't base my Proxy configuration on it.  None of the other controls return any text value.  For example, there is a "b/s" static control that is Static10, but it doesn't return a value.  AU3Info also has no trouble retrieving the values from this control either and the text value appears to be correct just as the Static1 value in Au3Info appears to be correct.  I've also tried using WinGetText on this dialog window and it fails as well leaving me with no text at all.

I originally thought that I was matching the wrong window, so I read the exact Window Title with WinGetTitle (i.e. which seems to work) and then changed to  Opt( "WinTitleMatchMode", 3) to match exact.  It didn't change the behavior.  It was exactly the same.  I've tried using Advanced mode on the title and using [CLASS:#32770] to identify the window with the exact same behavior.  So, presumably the window matching is correct.

I imagine it is something simple I don't understand as when I'm stumped this long that is almost always the case.  I simply don't understand why the anticipated values aren't being returned.  Au4Info seems to have no problem pulling the data from the dialog.

Thanks for any help you can give.


            
        

        

        
    

    

    




    Link to comment
    
        
    
    
    

    
    Share on other sites
    

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    


    
    More sharing options...

    


    

                    
                    
                    
                

                    

                    
                    





    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


JohnOne
            
            
                Posted 
                
            
        
    
    
        


JohnOne
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Active Members
                
            
            
                
                    
                        
                            
                                
                            
                                 17.4k
                            
                                
                            
                        
                        
                            
                                
                                    
                                        
                                        119
                                
                                    
                                
                            
                        
                    
                
            
            
                

    
    
        
Number #1
    
    

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                    (edited)
                
                
            
        
    

    

    

    
        
        
            Your code does not really make sense, because there are all kinds of variables undeclared.

If you just want to know if disconnected or connected then

If StringInStr(WinGetText("win"),"Disconnected") Then 
   ;connected = false
Else
   ;connected = true
EndIf


            
                


    Edited  by JohnOne
    
    

            
        

        

        
            

    
        

        
            

    AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 



    Monkey's are, like, natures humans.


        
    

        
    

    

    




    Link to comment
    
        
    
    
    

    
    Share on other sites
    

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    


    
    More sharing options...

    


    

                    
                    
                    
                

                    

                    
                    





    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


dalelengle
            
            
                Posted 
                
            
        
    
    
        


dalelengle
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Members
                
            
            
                
                    
                        
                            
                                
                            
                                 6
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                        Author
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                
            
        
    

    

    

    
        
        
            Over the past two days I have tried your idea in various variations four times.  That is how I was able to state in my first post,

...  I've also tried using WinGetText on this dialog window and it fails as well leaving me with no text at all.


I presume that "win" should be the Title of the window, which in this case, is "BIG-IP Edge Client".  Correct?  At least that was how I tried it.  I used the text parameter filled in "Connected" and not filled in "".  Every way that I try to use the WinGetText function, it fails and leaves me with a blank string in the variable.  I used the exact format that you did in your post.  From my trials of your idea that I did prior to my first post...

                                 If WinExists($VPNWindowTitle) Then
                                        MsgBox( 0, "Window Exists", $VPNWindowTitle)
                                        $VPNWindowTitle = WinGetTitle($VPNWindowTitle)
                                        Opt( "WinTitleMatchMode", 3)
                                        $VPNWindowText = WinGetText($VPNWindowTitle, "")
                                        MsgBox( 0, "Full Window Title", $VPNWindowTitle)
                                        MsgBox( 0, "VPN Window Text", $VPNWindowText)
                                        If StingInStr(WinGetText($VPNWindowTitle), $VPNSessionText) Then

As far as the code not making sense, both the above code and the code in the first post are just snippets from a larger program. I don't even think that I used the entire IF..ENDIF construct in the first post snippet and I know I didn't in the one above, which is a variation on the code in the first snippet using WinGetText rather than ControlGetText. These posts are long enough without worrying about well-formed code. This is the code that I'm having trouble with. The rest of the 1600+ lines of code work well and I am having no trouble with them. As far as the variables go, they are set by reading an ini file. The snippet of code that reads the part of the ini file responsible for loading these variables is below.

$inivalue = IniRead ( ".Configuration.ini", "Configuration", "ProxyWithVPNSession", "Not Found" )
    If $inivalue <> "Not Found" then
        $ProxywithVPN = "T"
        $VPNProcessName = StringLeft($inivalue, StringInStr($inivalue,"|")-1)
        $VPNProxySession = StringMid($inivalue, StringInStr($inivalue,"|")+1, (StringInStr($inivalue,"|",1,2)-1)-StringInStr($inivalue,"|"))
        $VPNNoProxySession = StringMid($inivalue, StringInStr($inivalue, "|",1,2)+1)
    Else
        $ProxywithVPN = "F"
        $VPNProcessName = ""
        $VPNProxySession = ""
        $VPNNoProxySession = ""
    Endif
    $inivalue = IniRead ( ".Configuration.ini", "Configuration", "DetectVPNSession", "Not Found" )
    If $inivalue <> "Not Found" then
        If $inivalue = "Process" Then
            $DetectVPNSession = "T"
            $DetectVPNSessionType = "Process"
            $VPNWindowTitle = ""
            $VPNControlID = ""
            $VPNSessionText = ""
        Else
            If StringLeft($inivalue, StringInStr($inivalue,"|")-1) = "Title" Then
                $DetectVPNSession = "T"
                $DetectVPNSessionType = "Title"
                $VPNWindowTitle = StringMid($inivalue, StringInStr($inivalue,"|")+1, (StringInStr($inivalue,"|",1,2)-1)-StringInStr($inivalue,"|"))
                $VPNControlID = ""
                $VPNSessionText = StringMid($inivalue, StringInStr($inivalue, "|",1,2)+1)
            Else
                $DetectVPNSession = "T"
                $DetectVPNSessionType = "Control"
                $VPNWindowTitle = StringLeft($inivalue, StringInStr($inivalue,"|")-1)
                $VPNControlID = StringMid($inivalue, StringInStr($inivalue,"|")+1, (StringInStr($inivalue,"|",1,2)-1)-StringInStr($inivalue,"|"))
                $VPNSessionText = StringMid($inivalue, StringInStr($inivalue, "|",1,2)+1)
            EndIf
        EndIf
    Else
        $DetectVPNSession = "F"
        $VPNWindowTitle = ""
        $VPNControlID = ""
        $VPNSessionText = ""
    Endif

The ini file contents currently are as follows:

[Configuration]

ProxyWithVPNSession = "f5fpclientW.exe|PROXY|NOPROXY"
DetectVPNSession = "BIG-IP Edge Client|Static1|Connected"

Again this is not all of the Configuration ini file, but only the part that pertains to this problem. When the above code is executed against the above ini, it leaves you with the following values for the variables.

$ProxywithVPN = "T"

$VPNProcessName = "f5fpclientW.exe" ;Name of the process for Big-IP Edge Client

$VPNProxySession = "PROXY" ;Standin for proxy settings

$VPNNoProxySession = "NOPROXY" ; Standin for no proxy settings

$DetectVPNSession = "T"

$VPNWindowTitle = "BIG-IP Edge Client" ;Window Title

$VPNControlID = "Static1" ; Control identifier using ClassnameNN format, but I've tried others including Advanced Mode and ID

$VPNSessionText = "Connected" ; Text that will indicate if the VPN Session is connected.

So much for the variables.

As I look at the behavior of these functions for the past 2 days, the only explanation that satisfies all of the behavior is that there is second window with such a similar title that I keep getting that window instead of the one that I'm trying to identify. Also, this window is not visible to me on the screen such that it must be hidden. I've tried using advanced mode for the ControlID using {ID:2040], which is the ID of this control according to Au3Info and it returns nothing, not "Activation" or "Loading...." So, based upon that, what seems most likely is that there is a hidden window with a Static1 control that does not use ID of 2040 and has as its possible values "Activation" and "Loading". However, since I can't see it, it is difficult to confirm my theory. Any ideas either on how I can correct the window identification, if that is the issue, or at least a way to confirm or deny my theory.

Thanks for the help

Link to comment
Share on other sites

Ok, I confirmed my theory. I decided to do the following:

If WinExists($VPNWindowTitle) Then
                                        MsgBox( 0, "Window Exists", $VPNWindowTitle)
                                        WinSetState ( $VPNWindowTitle, "", @SW_SHOW )
                                        $VPNWindowTitle = WinGetTitle($VPNWindowTitle)
                                        Opt( "WinTitleMatchMode", 3)
                                        $VPNWindowText = WinGetText($VPNWindowTitle, "")
                                        MsgBox( 0, "Full Window Title", $VPNWindowTitle)

And up popped a large grey blank window with a single static control (i.e. Static1) with "Loading..." as its text value. There is also a Cancel button on it. Nothing else. Now that it is visible, I can use Au3Info on it. The Summary from Au3Info is as follow:

>>>> Window <<<<
Title:    BIG-IP Edge Client™
Class:    #32770
Position:    614, 150
Size:    724, 612
Style:    0x94CF0044
ExStyle:    0x00010100
Handle:    0x0000000000040466

>>>> Control <<<<
Class:    Static
Instance:    1
ClassnameNN:    Static1
Name:    
Advanced (Class):    [CLASS:Static; INSTANCE:1]
ID:    1114
Text:    Loading...
Position:    2, 2
Size:    705, 541
ControlClick Coords:    26, 13
Style:    0x52010000
ExStyle:    0x00010004
Handle:    0x0000000000030492

>>>> Mouse <<<<
Position:    650, 195
Cursor ID:    0
Color:    0xF0F0F0

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
Cancel
Loading...


>>>> Hidden Text <<<<

Comparing this with the Au3Info Summary for my target window....

>>>> Window <<<<
Title:    BIG-IP Edge Client™
Class:    #32770
Position:    967, 14
Size:    561, 270
Style:    0x1CCA00C4
ExStyle:    0x00010101
Handle:    0x00000000000304A2

>>>> Control <<<<
Class:    Static
Instance:    1
ClassnameNN:    Static1
Name:    
Advanced (Class):    [CLASS:Static; INSTANCE:1]
ID:    2040
Text:    Disconnected
Position:    76, 17
Size:    323, 28
ControlClick Coords:    55, 20
Style:    0x5002C08D
ExStyle:    0x00000024
Handle:    0x000000000007052E

>>>> Mouse <<<<
Position:    1101, 76
Cursor ID:    0
Color:    0xE6FFFF

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
Connection
Auto-Connect
Connect
Disconnect
Change Server
Show Graph
View Details
Disconnected
Server: Philadelphia
Close a connection and disconnect.
Outbound Traffic
0 b/s
Inbound Traffic
0 b/s


>>>> Hidden Text <<<<
Traffic
1 minute ago
30 seconds ago
Current
Inbound: 0 B total (0% compression)
Throughput: 0 b/s
Outbound: 0 B total (0% compression)
Throughput: 0 b/s
Notifications

It is clear that the only real difference is the window handle, that it is hidden, and maybe the size if the size isn't changeable for this window. It appears not to be changeable, so perhaps it will work to identify the correct window. Now my task is to determine how to tell these two windows apart in my code. Suggestions are welcome.

Thanks,

Link to comment
Share on other sites

This is resolved. Sorry that I bothered you. The code that fixed the issue is as follows:

If WinExists($VPNWindowTitle) Then
                                        $VPNWindowHandleArray = WinList($VPNWindowTitle)
                                        For $i = 1 To $VPNWindowHandleArray[0][0]
                                            If $VPNWindowHandleArray[$i][0] <> "" And IsVisible($VPNWindowHandleArray[$i][1]) Then
                                                $VPNWindowHandle = $VPNWindowHandleArray[$i][1]
                                                $VPNWindowTitle = $VPNWindowHandleArray[$i][0]
                                            EndIf
                                        Next
                                        If StringInStr(ControlGetText($VPNWindowHandle, "", $VPNControlID), $VPNSessionText, 1) > 0 Then

The above code accesses the text from a control. For the Window Text method here is the code I used to resolve it. Variation on the theme.

If WinExists($VPNWindowTitle) Then
                                        $VPNWindowHandleArray = WinList($VPNWindowTitle)
                                        For $i = 1 To $VPNWindowHandleArray[0][0]
                                            If $VPNWindowHandleArray[$i][0] <> "" And IsVisible($VPNWindowHandleArray[$i][1]) Then
                                                $VPNWindowHandle = $VPNWindowHandleArray[$i][1]
                                                $VPNWindowTitle = $VPNWindowHandleArray[$i][0]
                                            EndIf
                                        Next
                                        If StringInStr(WinGetText($VPNWindowHandle, ""), $VPNSessionText, 1) > 0 Then

It gets an array of matching windows and then accesses the visible one using the IsVisible function that is on the example of the WinList help file. The IsVisible function is at the end of the program. I made no changes to it from the AutoIT helpfile on WinList. After it identifies the correct window, it grabs the handle and does all remaining window management functions using the window handle instead of the Title.

Thanks for the help. Sorry to have bothered you all.

Link to comment
Share on other sites

JohnOne,

You're obviously a bright guy and I'm sure that you've helped a lot of people on this forum. For me, not so much. From your first answer in which my code didn't make sense to this last cryptographic one about why I need a loop, you were no help to me in this forum. It seems more like you were intent on explaining to me how superior you are. While that may well be true, no one likes a person who must remind everyone about it.

As for your loop comment, I presume that you're talking about using advanced mode to identify the 2nd Instance of the window title. I considered that and decided that someday on a different machine or an upgraded OS, for whatever reason, the title matching algorithm might start matching the two windows in opposite order breaking my code. I could avoid that by allowing for the code to resubmit the advanced instance number incremented by 1 in the event of an error. So, I decided on the loop so that I could examine all of them. Whether the loop is used to examine the windows or checking for errors and resubmitting the "Instance" error checking, it is still a loop.

If my assumption above is incorrect and that wasn't what you were thinking, perhaps you could actually describe your idea. That would be much more helpful than asking me not to sleep until I figured out why I didn't need a loop.

The code works perfectly now and I'm not likely to revisit it either way.

Thanks,

dalelengle

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...