Jump to content

Check user authentication to windows share


 Share

Recommended Posts

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

Link to comment
Share on other sites

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

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

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

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?

Link to comment
Share on other sites

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

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

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