Sign in to follow this  
Followers 0
EndFunc

Custom Error message

11 posts in this topic

I've been working on a program for a while now. Works great. Problem is I know the program won't work in certain environments because its designed to work in a MS Domain.

When the script is compiled and the app is not ran in that environment you get the autoit error Variable must be of type "Object".

How do I not show an AutoIT error but my own error when the compiled script is ran so they know what's the problem? Can't see to find that. Using @error at the start of the script doesn't seem to catch it.


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here's an example of where someone used a custom error handler in their script...

Otherwise you can add this to the top of your script if you want a quick and easy error handler (this is mostly useful if you just need to debug it yourself):

#include <IE.au3>
_IEErrorHandlerRegister()
Edited by exodius

Share this post


Link to post
Share on other sites

You could check if your computer is in a domain or not. Please see this example.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Sweet. Thanks for the tips.


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

You need 2 scripts (they can be integrated using functions). The first one runs the second using /ErrToStdout or whatever that commandline is (I think thats it), and runs in the background checking the std stream. When the program ends, you can tell if its an error or not from the format of the last item sent to the stream. not sure how much sense that makes :)

Search the example scripts section, I think there are a few examples in there.

Alternatively, do it the normal way and use:

If Not IsObj($o) then Exit 0 * MsgBox (16, "Error", "Not on an MS Domain!!!")

Mat

Share this post


Link to post
Share on other sites

You could check if your computer is in a domain or not. Please see this example.

I tried doing something like this and couldn't really get it work correctly. I need an error handler that is not depending on any particular computer. Either just being part of the domain or maybe looking to see if it can make an ldap query connection. I tried to do that sorta but didn't get it work. It kept giving me the error and exiting the script.

Any other ideas on a Com handler?


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

I tried doing something like this and couldn't really get it work correctly. I need an error handler that is not depending on any particular computer. Either just being part of the domain or maybe looking to see if it can make an ldap query connection. I tried to do that sorta but didn't get it work. It kept giving me the error and exiting the script.

Any other ideas on a Com handler?

What isn't working with the available Com Handler option?

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

What isn't working with the available Com Handler option?

Hi Jos,

I guess Im not quite sure how to make it work correctly for me. Not that it doesn't work.

I haven't used many custom com error handlers in my scripts. I am trying to make it so that if you run the script on a normal computer not in a domain it will give a message box saying what i want then exit. It has to be run on a domain with ldap capabilities. Whatever I've tried doesn't seem to work.

So, I can't quite get what to check so it doesn't do that. Checking using @logonserver and things don't quite work.

Global $oMyError = ObjEvent("AutoIt.Error", "ComErrFunc"
;catch the error here is not in a domain and exit the script.

;My script here...

;com handler here
Func ComErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    Return SetError(1, $HexNumber, 0)
EndFunc   ;==>ComErrFunc

I'm not quite sure what I can put after the declared error handler to catch so that it triggers the message box instead of getting the AutoIt error Variable must be of type "Object".

I wrote over 1300 lines of code from scratch for the program and can't get a Com error. :)

Edited by EndFunc

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

The Com Error handler will catch the comm errors. To test if a variable contains really an object you either test for the @error when the Object is initialized or you test to see if the variable is an object : IsObj($var)

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

The Com Error handler will catch the comm errors. To test if a variable contains really an object you either test for the @error when the Object is initialized or you test to see if the variable is an object : IsObj($var)

When I do that I get an error still from AutoIt when its compiled on a computer with no access.

Variable must be of type "Object".:

Using this at the top of the script under the includes, doesn't seem to be working. The error is coming from one of the includes in the script.

Global $oMyError = ObjEvent("AutoIt.Error", "ComErrFunc") ;

If @error Then

MsgBox(16, "", "This program is designed to work in a Microsoft Active Directory environment." & @CR & _

"It also must be ran with administrative privleges. Contact your System Administrator.", 12)

Exit

EndIf


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

When I do that I get an error still from AutoIt when its compiled on a computer with no access.

Variable must be of type "Object".:

Using this at the top of the script under the includes, doesn't seem to be working. The error is coming from one of the includes in the script.

Global $oMyError = ObjEvent("AutoIt.Error", "ComErrFunc") ;

If @error Then

MsgBox(16, "", "This program is designed to work in a Microsoft Active Directory environment." & @CR & _

"It also must be ran with administrative privleges. Contact your System Administrator.", 12)

Exit

EndIf

You need to put the test where you do the LDAP Com initialisation and every time you set a variable that gets a Object returned.

example:

$Usr = ObjGet("LDAP://" & $UserDN)
$Ret = @error
If $Ret Then
    ; error handling
EndIf

-or-
If not IsObj($usr) then
    ; error handling
EndIf

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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