Jump to content

Script hangs after ShellExecute/Run results in Win dialogue box


bighero
 Share

Recommended Posts

Hi all,

Pretty much as the topic says. I'm writing a little script that includes the possibility an executed file results in a Windows error message e.g. 16 bit application, invalid error, etc.

The code is along the lines of the following:

ShellExecute("C:16bit.exe")
If WinExists("[CLASS:#32770]") Then
 $mytext = WinGetText("[CLASS:#32770]")
  if StringInStr($mytext, "OK") Then
   WinClose("[CLASS:#32770]")
   sleep(100)
  Else
   ;MsgBox(0, "", "nope")
   sleep(100)
  EndIf
EndIf

But I've noticed the script won't get past the ShellExecute/Run line, even if all that follows is a msgbox. I though AutoIt scripts would continue processing unless you specify RunWait, for example? I just want to be able to check for a Windows error message and move on...

To be clear, I've tried both Run and ShellExecute. Everything works fine it just won't go past the ShellExecute/Run line unless I manually close the error dialogue box.

Appreciate any help....

edit: excuse the Else, this used to be in a separate script that continuously looped.

edit2: also, this is not the actual script, this is my "test script" that I'm using to try out different things to fix the issue.

edit3: I've also tried Sleep commands

edit4: OS is Win7 64bit

Thanks,

Dan.

Edited by bighero
Link to comment
Share on other sites

If you are waiting for it to pop up with the nope message box, you need to move it one if up. Otherwise, its not hanging, it looks like its all executing in one moment.

EDIT: Aka you are not waiting long enough for the error to appear. Put a sleep in.

Edited by mattiej
Link to comment
Share on other sites

Either insert a Sleep after the Run/ShellExecute statement so the program can start and the window can pop up.

Or you do it in a loop to check for the window.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

This script (running NotePad) works fine for me.

Opt("TrayIconDebug", 1)
ShellExecute("Notepad")
If WinExists("[CLASS:#32770]") Then
    $mytext = WinGetText("[CLASS:#32770]")
    If StringInStr($mytext, "OK") Then
        WinClose("[CLASS:#32770]")
        Sleep(100)
    Else
        ;MsgBox(0, "", "nope")
        Sleep(100)
    EndIf
EndIf

Note the line

Opt("TrayIconDebug", 1)

This will show the currently executed line in the try icon.

Can you post the result?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Grateful for all of the input so far....

If it helps, the error message in question is "Unsupported 16-bit Application".

To be clear - this error is a result of the file I'm trying to execute. Not the AutoIt script itself. This little segment is intended to be a "what-if" clause that'll account for possible error messages when executing a series of files.

edit: pretty much ignore this post, also seeing it on invalid win32 app errors too...

Edited by bighero
Link to comment
Share on other sites

This script (running NotePad) works fine for me.

Opt("TrayIconDebug", 1)
ShellExecute("Notepad")
If WinExists("[CLASS:#32770]") Then
    $mytext = WinGetText("[CLASS:#32770]")
    If StringInStr($mytext, "OK") Then
        WinClose("[CLASS:#32770]")
        Sleep(100)
    Else
        ;MsgBox(0, "", "nope")
        Sleep(100)
    EndIf
EndIf

Note the line

Opt("TrayIconDebug", 1)

This will show the currently executed line in the try icon.

Can you post the result?

 

Line 5: ShellExecute("C:.......

The script works fine with something like Notepad, it's only when there's an error message. Create a text doc, rename as an exe and maybe you'll see what I am? Hopefully :D Othereise there's something unholy going on :S

Edited by bighero
Link to comment
Share on other sites

I see.

The message isn't being issued by the program but by Windows itself.

How about this. It checks ever 250ms for the popup:

Opt("TrayIconDebug", 1)
AdlibRegister("CheckPopUp", 250)
ShellExecute("Notepad")

Func CheckPopUp()
    If WinExists("[CLASS:#32770]") Then
        $mytext = WinGetText("[CLASS:#32770]")
        If StringInStr($mytext, "OK") Then
            WinClose("[CLASS:#32770]")
        Else
            ;MsgBox(0, "", "nope")
        EndIf
    EndIf
EndFunc   ;==>CheckPopUp

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

So this seems to be a blocking message.

Two things you could do:

  • Try to check if the Exe is 16 bit before starting it
  • Run the popup checker as a seprate compiled script. An example can be found in my OutlookEX UDF where I use the same approach to click away Outlook security warnings.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thanks, my original fix was a secondary script that closes any existing error messages and works like a charm. I was just hoping to bring that error check inside the main script so that I could possibly log the filename in question.

Link to comment
Share on other sites

You could call the popup checker from your main script and pass the processid of the mainscript.

This way you could automatically end the popup checker when the main script has ended.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

If I run the secondary script from within the main script, can I pass a variable across to it? Or maybe include it as an argument when launching the secondary script?

To qualify that, what I'm thinking is:

1st script

run(2nd script)

sleep(1000)

run(executable)

sleep(20000)

2nd script:

$sFilename = arg1/env var

sleep(5000)

 if error exists then

       write out $sFilename to log

endif

That way the secondary script won't be attempting anything until after the main script tries running the .exe. I won't have to continuously lop it as any error message will appear within a second or two. The second sleep in the 1st script should also ensure that I'm not spawning multiples of the 2nd script?

Edited by bighero
Link to comment
Share on other sites

Yes, you can pass parameters - simply check the help file for function "Run".

I wouldn't use sleep, but check in a loop.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Not that I know of.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I would use something like this. Script 1 starts the popup checker script and then starts Notepad, the checker script waits for the Notepad window (you need to change the title) and writes a MsgBox. When Script 1 ends the Checker script automatically ends as well.

Calling script:

$iPID = Run("checkpop.exe " & @AutoItPID & " " & @ScriptDir & "\Test.log")
ConsoleWrite($iPID & @CRLF)
Sleep(5000)
ShellExecute("Notepad")

Checker Script:

; #PROGRAM# =====================================================================================================================
; Name ..........: CheckPop
; Description ...: Check for Windows error pop ups
; Syntax.........: Run(CheckPop.exe $iPID [$sLogFile])
; Parameters ....: $iPIDsID  - The ProcessID of the calling script
;                  $sLogFile - Optional: Path for the log file. Default = @ScriptDir & "\CheckPop.txt"
; Return values .: Failure - Sets returns value:
;                  |1 - ProcessID is missing as first parameter
;                  |2 - Specified ProcessID does not exist at startup
; Author ........: water
; Modified ......: water
; Remarks .......: Compile this script into an exe. Default location is the directory where the calling script is located.
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Opt("TrayIconHide", 1)                              ; 0=show, 1=hide tray icon
Opt("WinSearchChildren", 1)                         ; 0=no, 1=search children also
Global $iPID                                        ; ProcessID of the calling script
Global $sLogFile = @ScriptDir & "\CheckPop.txt"     ; Default name of the log file
If $CmdLine[0] = 0 Then Exit 1                      ; No ProcessID was specified
$iPID = $CmdLine[1]                                 ; Store ProcessID of the calling script
If Not ProcessExists($iPID) Then Exit 2             ; If the process does not exist, exit with error
If $CmdLine[0] > 1 Then $sLogFile = $CmdLine[2]     ; Store log file name
While 1
    ; Check for the error window and log to the file
    If WinExists("Unbenannt - Editor") Then MsgBox(0, "", "Found!")
    Sleep(250)                                      ; Sleep before doing the next check
    If Not ProcessExists($iPID) Then Exit           ; Exit when calling program no longer exists
WEnd
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...