Jump to content

Recommended Posts

Posted

Under the general heading of 'There's gotta be a way', I've been exploring possible solutions to intercept the script abort message and, instead of the harsh 'Clang and X' abort message, display a reasonable message like the following:

"An unforeseen error has occurred that prevents this program from continuing.  It will now close without completing the requested operation."

Here's a UDF that's complex that I could never consider adding it to a production script.  My needs just aren't that complicated.  I applaud the intent, but think it needs great simplification for wide use.

Here's a simpler method that only removes 'AutoIt' from the heading on the message.  As shown below, I've modified it for my immediate use to give a one-step-better message to the user (no Clang ... no 'X').  For some reason, $sText cannot be altered, but $sTitle can.  0x00000030 is the code for the "!" message type.

My point is this: production scripts are thoroughly tested.  Any error condition that occurs is due to some condition outside of the realm of typical operation and will be rare.  Any such error needs to be handled graciously and without alarming the user.  Clang+X doesn't meet that need.

The very best solution would a universal one that could be invoked at a macro level (like #RequireAdmin) or maybe with an umbrella call (like _GDIPlus_Startup).

I hope that I've missed something and that this already exists, but I haven't found it.

Thanks in advance for any help.
 

AddHookApi("user32.dll", "MessageBoxW", "Intercept_MessageBoxW", "int", "hwnd;wstr;wstr;uint")
Func Intercept_MessageBoxW($hWnd, $sText, $sTitle, $iType)
    Local $aCall = DllCall("user32.dll", "int", "MessageBoxW", _
            "hwnd", $hWnd, _
            "wstr", $sText, _
            "wstr", StringReplace($sTitle, "AutoIt", "Error has occurred: Invalid ZIP file"), _
            "uint", 0x00000030)
    If @error Or Not $aCall[0] Then Return 0
    Return $aCall[0]
EndFunc

Interim solution.png

For reference: msdn link

Posted (edited)

Check out this thread and specifically @trancexx solution

 

when I read this thread title I thought of The Kraang from TMNT

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted

Indeed, the thread you've referenced is the one I cited as a reasonable starting point ... and have adapted to be an interim solution.  Have I missed something else?

 

Posted (edited)

nope. I was going to suggest something like @argumentum's solution. It should do what you need using the WinAPI stuff.

thanks for pointing this out to me! his solution is rather nice. I do like it. do the examples.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted
7 minutes ago, Earthshine said:

I was going to suggest something like @argumentum's solution.

I didn't find that solution in the thread.  How about a link? ... and to the examples you're referring to?

Sorry if I sound confused.

 

Posted (edited)

 It’s the one you said was too complex to implement. You linked it. When I get back to my desk I’ll post the link

works great on 7 and 10 so far for me

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted
Quote

It’s the one you said was too complex to implement.

OK ... that clears it up.  No need for a link.  Sorry I missed that.

Thanks for your responses!

Posted (edited)

You will need to study the example code and you should be able to get an idea of what you need to do In order to deal with it or just bypass it and log it. Whatever your needs are

The examples are really nice and demonstrate just what you were trying to do

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted

After several adjustments to the RegExp (more than I will admit to), the following statements produce the message shown below.

I'll welcome any simplifying adjustment or suggestions for a different method.  But this method appears to meet my immediate requirement.

AddHookApi("user32.dll", "MessageBoxW", "Intercept_MessageBoxW", "int", "hwnd;wstr;wstr;uint")
Func Intercept_MessageBoxW($hWnd, $sText, $sTitle, $iType)
    Local $aCall = DllCall("user32.dll", "int", "MessageBoxW", _
            "hwnd", $hWnd, _
            "wstr", StringRegExpReplace(StringRegExpReplace($sText, "\([^)]*\)", ""), "(.*)\bError\b(.*)", "An unsupported file condition has been encounted that prevents this program from continuing.  It will now close without completing the requested operation."), _
            "wstr", StringReplace($sTitle, "AutoIt", "Invalid ZIP file"), _
            "uint", 0x00000030)
    If @error Or Not $aCall[0] Then Return 0
    Return $aCall[0]
EndFunc

Interim result.PNG

Posted (edited)

I've made a change to the RegExp to avoid modifying any message message text with the word 'Error'.  It now modifies only those with 'Error: '.

StringRegExpReplace(StringRegExpReplace($sText, "\([^)]*\)", ""), "(.*)\bError: \b(.*)", "An unsupported file condition has been encounted that prevents this program from continuing.  It will now close without completing the requested operation."), _

Thanks to ViciousXUSMC for the link to RegEx101 dot com, where I was able to confirm the improved RegExp.

Edited by qwert

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