Jump to content

Recommended Posts

Posted

Dear all,

I am new to the forum.  Can anyone show me how to run a command upon some text shows up in the status bar of a window?

e.g. close the window/program when the status bar shows the word "finished".

I tried:

If Winexists ("[Finished]") Then Winclose ("Program - ", "")

but then some error pops up like: if winexists (      - ^ error   subscript used on non-accessible variable

Perhaps my syntax is wrong?

Thank you!

Laurence

Posted (edited)

@laurence77at

can you show image of  window your using.

just use StatusbarGetText:exsample below:

#include <MsgBoxConstants.au3>
Local $Part = 1;The "part" number of the status bar to read - the default is 1. 1 is the first possible part and usually the one that contains the useful messages like "Ready" "Loading...", etc.
Local $sText = StatusbarGetText("title of window here",'',$Part)
MsgBox($MB_SYSTEMMODAL, "", "status bar says: " & $sText)

e.g. close the window/program when the status bar shows the word "finished":

#include <MsgBoxConstants.au3>
Local $Part = 1;The "part" number of the status bar to read - the default is 1. 1 is the first possible part and usually the one that contains the useful messages like "Ready" "Loading...", etc.
While 1
Local $sText = StatusbarGetText("title of window here",'',$Part)
if  $sText = "Finished" Then
WinClose("Program - ","")
ExitLoop
Endif
Sleep(50)
Wend

 

Edited by ad777

none

Posted

Thanks ad777,

Excellent. I guess the above loop will keep monitoring the status bar till the desired text appears?

How about if the full text just contains the words "Finished"?
(the status bar not exactly shows "Finished", but maybe something like "Finished at here or there", or only contains the words "Finished")

if $sText =

Thanks!

Posted
2 hours ago, laurence77at said:

How about if the full text just contains the words "Finished"?
(the status bar not exactly shows "Finished", but maybe something like "Finished at here or there", or only contains the words "Finished")

if $sText =

Thanks!

Add StringInStr As @Nine Say's :See script below:

#include <MsgBoxConstants.au3>
Local $Part = 1;The "part" number of the status bar to read - the default is 1. 1 is the first possible part and usually the one that contains the useful messages like "Ready" "Loading...", etc.
While 1
Local $sText = StatusbarGetText("title of window here",'',$Part)
Local $word = "Finished"
if StringInStr($sText,$word) Then
WinClose("Program - ","")
ExitLoop
Endif
Sleep(50)
Wend

 

none

Posted

Further to the above question, I want to further relax the criteria so that when the text appears in any part of the window, it works.

I have tried to use Wingettext , but an error pops up:

 

Local $Part = 1;The "part" number of the status bar to read - the default is 1. 1 is the first possible part and usually the one that contains the useful messages like "Ready" "Loading...", etc.
While 1
Local $sText = WinGetText("Program",'',$Part)
; the below $word = and $sText = will make all text containing "finished" to function!
Local $word = "Finished"
if StringInStr($sText,$word) Then
WinKill ("Program")
ExitLoop
EndIf
Sleep(50)
Wend

 

Any idea?

Thanks.

 

 

 

 

 

 

 

 

Posted

@laurence77at

Next Time you should read help file.

Url for WinGetText:https://www.autoitscript.com/autoit3/docs/functions/WinGetText.htm

While 1
    Local $sText = WinGetText("Program", '')
    ; the below $word = and $sText = will make all text containing "finished" to function!
    Local $word = "Finished"
    If StringInStr($sText, $word) Then
        WinKill("Program")
        ExitLoop
    EndIf
    Sleep(50)
WEnd

 

none

Posted

Thanks.  

I am using the below call for opening an excel workbook,

 

#include<excel.au3>
Local $Var = "D:\workbook.xls"

Local $oExcel_1 = _Excel_Open()
_Excel_BookOpen($oExcel_1, $var)

 

the book opened, but returned an autoit error:

 

Line 227 (File "C:\Program Files\Autoit3\Include\Excel.au3

$oExcel.windows($oWorkbook.Name).Visible = $bVisible
$oExcel.windows($oWorkbook.Name)^Error

Error: Variable must be of type "Object",

 

Any idea??

 

Posted (edited)

Hi Nine,

The code is there, it is just that simple - to open a excel workbook with a path and filename!

I searched over and over the forum and help but still don't know why the error pops up, however, the file opened.

I even tried the 'on error go to' you made earlier but to no avail....

Please help.

#include<excel.au3>
Local $Var = "D:\workbook.xls"

Local $oExcel_1 = _Excel_Open()
_Excel_BookOpen($oExcel_1, $var)

 

 

 

 

 

 

Edited by laurence77at
Posted

  

This is a solution I get from this post :

And I had this script from the topic : (Whitch helped me a lot in lot of similar situation.)

It could react the same with your shell console. You have to redefine the code as you need.

#include <constants.au3>
#include <string.au3>
#RequireAdmin

; Use RunAs if you want use a fixed username/password within the script:
; Global $hPowerShellPID = RunAs("UserName", "Domain", "Password", "", "powershell.exe", '', @SW_HIDE, BitOR($STDIN_CHILD, $STDERR_MERGED))

; or use #RequireAdmin and a simple Run Statement to enter Admin credentials (if needed) at runtime
; Here we start a "permanent" powershell prompt with redirected streams
Global $hPowerShellPID = Run("powershell.exe", '', @SW_HIDE, BitOR($STDIN_CHILD, $STDERR_MERGED))

; this little loop is to wait for the "welcome" message from powershell
; just a way to be sure that the powershell is running and "streaming"
Do
    StdoutRead($hPowerShellPID)
Until @extended ; out stream started

; example:
; Here we "execute a command via the Powershell that is running in background...
; ...and we get back to resulting output
Local $Out = _Run_Cmdlet("Get-ItemPropertyValue 'Registry::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' -Name 'EnableLUA'", $hPowerShellPID)
ConsoleWrite($Out)

; here another command
ConsoleWrite(_Run_Cmdlet("dir c:\", $hPowerShellPID))

; .... and so on ...

; this function execute the passed powershell command and returns the resulting output
Func _Run_Cmdlet($sCmd, ByRef $hPS)
    Local $sStdOut = ''
    ; we insert a start and an end message in order to identify the "body" of the result of the command executed
    $sCmd = 'write-host "->StartOfStream<-"; ' & $sCmd & '; write-host "->EndOfStream<-"' & @CRLF
    StdinWrite($hPS, $sCmd)
    Do
        Sleep(250)
        $sStdOut &= StdoutRead($hPS)
        ; the presence of the known end message signals the end of the execution
    Until StringInStr($sStdOut, "->EndOfStream<-" & @LF)
    ; return only the body of the outpu of the passed command
    Return _StringBetween($sStdOut, "->StartOfStream<-" & @LF, "->EndOfStream<-" & @LF)[0]
EndFunc   ;==>_Run_Cmdlet

I'm sure you could done your goal with this ;)

 

Enjoy.

Thanks @Gianni btw.

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - 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

 

Posted

Thank you Junkew and Caramen, I finally found the below post that solved the "bug":

Simply by changing the Excel.au3 with the updated code avoided the error.

Should this be included in the include folder in future autoit releases?

Thanks.

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
  • Recently Browsing   0 members

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