Jump to content

Custom Error message


EndFunc
 Share

Recommended Posts

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.
Link to comment
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 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

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

Link to comment
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.
Link to comment
Share on other sites

  • Developers

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?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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.
Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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