Sign in to follow this  
Followers 0
PaulPerkins

Reading contents of status bar

17 posts in this topic

I'm trying to StatusBarGetText() to read the contents of a standard msctls_statusbar32 status bar control in a Win32 app. Your AutoIt v3 Window Info tool correctly sees the status bar text under that tool's "StatusBar" tab as the values of Property 2 and Property 3 fields. With the Win32 app open and in focus, I've tried the following code which gets past the error code but the value of x$ is always a blank string:

AutoItSetOption("WinTitleMatchMode", 2)

$x = StatusbarGetText("Untitled")

if @error = 1 Then

msgbox(0,"Error", "Error: No text could be read")

Exit

EndIf

MsgBox(0, "Status Bar 1", "Status bar says:", $x)

Any suggestions? If the Window Info Tool sees the control, sees the text in the StatusBar field, is there another way to read that text within a script?

Thank you for any help you can provide.

Paul Perkins

Share this post


Link to post
Share on other sites



I'm trying to StatusBarGetText() to read the contents of a standard msctls_statusbar32 status bar control in a Win32 app. Your AutoIt v3 Window Info tool correctly sees the status bar text under that tool's "StatusBar" tab as the values of Property 2 and Property 3 fields. With the Win32 app open and in focus, I've tried the following code which gets past the error code but the value of x$ is always a blank string:

AutoItSetOption("WinTitleMatchMode", 2)

$x = StatusbarGetText("Untitled")

if @error = 1 Then

msgbox(0,"Error", "Error: No text could be read")

Exit

EndIf

MsgBox(0, "Status Bar 1", "Status bar says:", $x)

Any suggestions? If the Window Info Tool sees the control, sees the text in the StatusBar field, is there another way to read that text within a script?

Thank you for any help you can provide.

Paul Perkins

Did you read the Comments section under StatusBarGetText() in the help file?

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Did you read the Comments section under StatusBarGetText() in the help file?

:D

Thank you for your reply. Yes, before posting here, I read the helpfile (and the remarks section) as well as searched for answers posted previously; further, I tried using ControlGetText but that didn't work, either. The Win32 app's status bar is the common control msctls_statusbar32 (not a special version).

I need help because the "text" in the StatusBar is blank (I am trying to read the Property 2 and Property 3 values as shown on the StatusBar tab of the AutoIt Window Information Tool).

Thank you.

Paul Perkins

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Bummer, 3 years and no results? Time to revive. I'm having a similar problem as discussed here and on other threads. I have read the help file, perhaps not comprehended fully though. I get success in some situations and not in others (see below) with the same syntax. Win7 Pro 64bit.

I have a program which I want to....

1. see if it's running

a.start it if it's not

2. read it's status bar

b.do different things depending on it's status

If the program is not running, and autoIT opens it, StatusbarGetText works....If however, it's already running, StatusBarGetText() returns empty. I am using the AutoIT Window info as well. Funky that it works in one situation, and not in the other.

Edited by patmo141

Share this post


Link to post
Share on other sites

What's the program you're trying to read from and what code are you using to do it?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

It's a VPN client (Cisco AnyConnect VPN). Needs to be logged in for my script

This is the code that does not work...I get a blank message box or nothing printed to the console

Func _CheckVPN()
    Local $status
    Local $process = "vpnui.exe"
    Local $PID = ProcessExists($process)

    If $PID <> 0 Then ;the process exists so lets check it's status
        ;MsgBox(0,"vpn","I exist")
        WinActivate("Cisco AnyConnect VPN Client")
        $status = StatusbarGetText("Cisco AnyConnect VPN Client")
        ConsoleWrite($status)
        Local $ret[2]
        $ret[0] = $PID
        $ret[1] = $status
        Return $status ;later i would like to return $ret
    Else
        Return 0
    EndIf
EndFunc

This is the code that does work...but only when the VPN is not running before hand.

$mypassword = "St3almyidentity" ;not really my password
$process = "vpnui.exe"
$PID = ProcessExists($process)

;a list of options
Local $opt[3]
$opt[0] = "Ready to connect"
$opt[1] = "Please enter your username and password"
$opt[2] = "VPN session established"

If $PID <> 0 Then
    MsgBox(0,"VPN","The VPN is Running")
    $status = StatusbarGetText("Cisco AnyConnect VPN Client")
    ConsoleWrite($status)
Else
    MsgBox(0,"VPN","The VPN is not Running")
    $VPNDir = "C:\Program Files (x86)\Cisco\Cisco AnyConnect VPN Client\"
    $PID = Run($VPNDir & "vpnui.exe")
    WinWait("Cisco AnyConnect VPN Client")
    $status = StatusbarGetText("Cisco AnyConnect VPN Client")
    ConsoleWrite($status)

    If StringInStr($status, $opt[0]) Then ControlClick("Cisco AnyConnect VPN Client","","[CLASS:Button; TEXT:Select]")
    $status = StatusbarGetText("Cisco AnyConnect VPN Client")
    $counter = 0
    While Not StringInStr($status, $opt[1])
        $counter += 1
        Sleep(100)
        $status = StatusbarGetText("Cisco AnyConnect VPN Client")
    WEnd
    ControlSetText("Cisco AnyConnect VPN Client","","[CLASS:Edit; Instance:3]", $mypassword)
    ControlClick("Cisco AnyConnect VPN Client","","[CLASS:Button; TEXT:Connect]")
    $status = StatusbarGetText("Cisco AnyConnect VPN Client")
    ConsoleWrite($status)
EndIf

Share this post


Link to post
Share on other sites

Check the PID for the return from the ProcessExists and see if it's actually the correct PID for the window you want. It's possible there's more than one, usually a hidden window that doesn't show up. A ProcessList command might help trouble shoot this if there is more than one process with the same name.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

First, I appreciate your help. That didn't seem to be the problem, In all situatiuons, process lists only returns one item. It did help me diagnose the problem a little more specifically.

Once the VPN software is logged in and it's status is "VPN Session established..." I can no longer retrieve the status but for all the other options before the connection is established, it reads the status correctly. I'm thinking that once it's connected, perhaps the VPN software changes it's "availability" so to speak. Eg, not allowing it's status to be read.

Share this post


Link to post
Share on other sites

Also, it seems once I disconnect, I can no longer read the statusbar. It seems the action of connecting to the VPN for the first time after the program is started, it no longer works with StatusbarGetText or ControlGetText. So it's not the actual state of the program, its the history, whether or not it has been connected.

Share this post


Link to post
Share on other sites

Does the AU3Info program show you anything on the Status bar tab? It might be that the status bar text isn't in the first location after it connects, and you'd need to use StatusbarGetText("Cisco AnyConnect VPN Client", "", 2) (or some other part of the bar) to get the text.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

@BrewManNH

The AutoIT V3 Window shows the status bar correctly all the time. That's why I've been so perplexed and reluctant to try to work around. I should have mentioned that in my original problem description. I've tried putting different indices as the "part" argument for StatusbarGetText as indicated by the helpfile but I need to be more systematic about it. I think I tried 1,2,3,4. The thing is, 1 gives the correct results some times, but not all the time. I think I tried this before I realized it's more related to the history of the program.

@Zedna

I think I did..Check post in the first code block I'm using "WinActivate". Are you envisioning something different?

Share this post


Link to post
Share on other sites

@Zedna

I think I did..Check post in the first code block I'm using "WinActivate". Are you envisioning something different?

Add also WinWaitActive and add these to ALL needed code branches.

Share this post


Link to post
Share on other sites

OK, I have reduced my code to one "branch" and simplified it for diagnostic purposes. It includes WinActivate and WinWaitActive and simply writes some info to the console and doesn't return anything. The steps for manually logging into the VPN in order with the statuses that appear is as follows (the context in which it will be used later)

Action0. Open the program

Status0: "Ready to Connect"

Action1: Select a VPN, click select

Status1: "Contacting _______________"

Status2: "Please enter your username and password"

Action2: Enter usernamen, pword, submit

Status3: "Establishing VPN Session"

Status4: "Checking ....

....

....

StatusFinal: "VPN Session esablished to ...."

##########################################

############ Results #############

0. All status scenarios are reported correctly by AutoIT Window Info

1. If I open the VPN (Action 0), Status0 is read correctly by all of the methods below

2. If I Select VPN (Action 1), Status2 is read correctly by all of the methods below

3. If I enter my credentials (Action2), StatusFInal is not reported or retreived by any of the methods

4. If I then disconnect the VPN, which returns the status bar to Status0, None of the methods are able to read the status bar.

_CheckVPN()


Func _CheckVPN()
    Local $name = "Cisco AnyConnect VPN Client"
    Local $process = "vpnui.exe"
    Local $status
    Local $PID = ProcessExists($process)

    ConsoleWrite("Starting  :  ")
    If $PID Then ;the process exists so lets check it's status
        Local $hWnd = WinGetHandle($name) ;perhaps some handling might be better?
        If @error Then ConsoleWrite("Failed to get window")
        AutoITSetOption("WinDetectHiddenText",1)
        WinActivate($name)
        WinWaitActive($name)


        ;here are all the different methods I tried, all work prior to the VPN establishing a connection

        $status = StatusbarGetText("Cisco AnyConnect VPN Client")
        ;$status = ControlGetText($name,"","[CLASS:msctls_statusbar32; INSTANCE:1]")
        ;$status = ControlGetText($name,"","[CLASS:msctls_statusbar32; ID:59393]")

        ConsoleWrite("Status:  " & $status)


    Else
        ConsoleWrite("no PID, this shouldn't be happening")
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

What happened to Status3 & 4? It's possible that the VPN client is opening a new window when it connects and then reruns itself.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

What happened to Status3 & 4?

Status 3 and 4...5,6 (not sure how many) happen progressively and quite quickly while it's connecting. Since I wasn't monitoring it continuously, rather doing the step by hand, running _CheckVPN() by hitting f5.

It's possible that the VPN client is opening a new window when it connects and then reruns itself.

That my be what is going on. But, I added another method and now it works. I was trying to use "WinGetState" and using the title of the window and it was returning 0 so I checked the @error and it wasn't able to find the window. So tried using the advanced settings for the window and it started giving me the correct state. That made me think perhaps it's not the control/statusbar that was having trouble, but the window title. Sure enough, this works in all situations described above.

$status = StatusbarGetText("[CLASS:VPNUI]")
Edited by patmo141

Share this post


Link to post
Share on other sites

Good catch.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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