Jump to content
Sign in to follow this  
Sardinha

Check user authentication to windows share

Recommended Posts

Sardinha

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]
EndIf

And 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)^ ERROR

Well, 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

Share this post


Link to post
Share on other sites
Sardinha

Hello everyone.

I really need some help.

Does someone know anything about this issue?

Best regards!

Share this post


Link to post
Share on other sites
water

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 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
jdelaney

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.

Share this post


Link to post
Share on other sites
Sardinha

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 by Sardinha

Share this post


Link to post
Share on other sites
water

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 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Sardinha

jdelaney, I think I get it now how DriveMapAdd function works.

I think my problem is solved.

Best regards.

Share this post


Link to post
Share on other sites
Sardinha

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

I can update to Beta version. Is it stable?

Share this post


Link to post
Share on other sites
water

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 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Sardinha

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.

Share this post


Link to post
Share on other sites
water

The second format as described in ObjEvent is what you need.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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  

×