Sardinha Posted January 24, 2013 Share Posted January 24, 2013 Hello everyone.I'm trying to connect to a windows share (\\print) but if my authentication fails, for example, wrong username or password, how can i catch that error?The problem is that when executing the script (exe. file), if i insert wrong credentials, the error message is from Autoit program and not the message i would like to pop up (code above) if there is some problem with the authentication.Here is a sample of my code:;Here I try connect to the server \\print with username and password $WshNetwork = ObjCreate("WScript.Network") $WshNetwork.MapNetworkDrive("", "\\print", True, $username, $password)The values of $username and $password are filled from an Inputbox.So, after that code i tried to catch the error like this:if @error Then [indent=1]MsgBox(16, "", "Authentication error!")[/indent] EndIfAnd by the way, the error i got from the console is this one:C:\Users\user\Desktop\test.au3 (33) : ==> The requested action with this object has failed.:$WshNetwork.MapNetworkDrive( "","\\print",True, $username, $password)$WshNetwork.MapNetworkDrive( "","\\print",True, $username, $password)^ ERRORWell, the error is happening, but is there some way to catch the error from the code and send an alert (Msgbox)?Thank you for your help and time,Sardinha Link to comment Share on other sites More sharing options...
Sardinha Posted January 24, 2013 Author Share Posted January 24, 2013 Hello everyone. I really need some help. Does someone know anything about this issue? Best regards! Link to comment Share on other sites More sharing options...
water Posted January 24, 2013 Share Posted January 24, 2013 Please wait at least 24 hours before you bump your thread!This not a 7x24 support forum! My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
jdelaney Posted January 24, 2013 Share Posted January 24, 2013 You can use function= DriveMapAdd from helpfile: Success: Returns 1. (See Remarks) Failure: Returns 0 if a new mapping could not be created and sets @error (see below). (See Remarks) When the function fails (returns 0) @error contains extended information: 1 = Undefined / Other error. @extended set with Windows API return 2 = Access to the remote share was denied 3 = The device is already assigned 4 = Invalid device name 5 = Invalid remote share 6 = Invalid password IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Sardinha Posted January 25, 2013 Author Share Posted January 25, 2013 (edited) Please wait at least 24 hours before you bump your thread! This not a 7x24 support forum! You're right Water. I apologize for the bump. jdelaney, thank you for the help. I already tried the DriveMapAdd function. The issue here is that I'm using the object $WshNetwork to add a printer and stuff like that. For example: $WshNetwork.AddWindowsPrinterConnection("\\" & $strServer & "\UNIVERSALPRINTER") $WshNetwork.SetDefaultPrinter("\\" & $strServer & "\UNIVERSALPRINTER") Any suggestion? Best regards, S. Edited January 25, 2013 by Sardinha Link to comment Share on other sites More sharing options...
water Posted January 25, 2013 Share Posted January 25, 2013 It depends on the AutoIt version you use. Up to 3.3.8.1 you need a COM error handler. Please see function ObjEvent. It describes how to implement a COM error handler. The latest AutoIt Beta version doesn't crash any more but sets @error for you to check. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Sardinha Posted January 25, 2013 Author Share Posted January 25, 2013 jdelaney, I think I get it now how DriveMapAdd function works. I think my problem is solved. Best regards. Link to comment Share on other sites More sharing options...
Sardinha Posted January 25, 2013 Author Share Posted January 25, 2013 It depends on the AutoIt version you use.Up to 3.3.8.1 you need a COM error handler. Please see function ObjEvent. It describes how to implement a COM error handler.The latest AutoIt Beta version doesn't crash any more but sets @error for you to check.Thank you Water.Yes, my version is 3.3.8.1I can update to Beta version. Is it stable? Link to comment Share on other sites More sharing options...
water Posted January 25, 2013 Share Posted January 25, 2013 As stable as a Beta can be. But if you prefer to work with 3.3.8.1 it's quite easy to implement a COM error handler. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Sardinha Posted January 25, 2013 Author Share Posted January 25, 2013 Thank you water again. I can search about the COM error handler for 3.3.8.1, but if you have URL with the explanation, and if you don't mind to share with me, i would appreciate Cheers. Link to comment Share on other sites More sharing options...
water Posted January 25, 2013 Share Posted January 25, 2013 The second format as described in ObjEvent is what you need. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now