Sign in to follow this  
Followers 0
goonia

Need help to map drive

11 posts in this topic

Hello,

I need your help to create a script.

Im a beginner and my knowledge in scripting are close to 0

Here is what I need :

Current situation :

Users Bob and Joe are using the same PC (they work in 2 teams) they log in windows with their domain accounts and the netlogon script automatically map the folder \\SRV01\SHARE

Those will have now to work with an application that needs to work with a generic local account but they still need to have access to the shared folder. As I can not create a generic domain account I need to have a script :

- which ask user for his username + password

- map the folder

In order to do something like under DOS : net use * \\SRV01\SHARE password /user:domain\bob (I dont want users to map manually)

Is it possible to do that ?

Thanks in advance

Share this post


Link to post
Share on other sites



How about this (untested... :lmao: )

#include<process.au3>

$user = @UserName
$pass = InputBox("Passwortd","Please enter your network password")

; DOS-Version: _rundos("net use * \\SRV01\SHARE " & password & " /user:domain" & $bob)

; AutoIt-Version
DriveMapAdd( "*", "\\SRV01\SHARE" ,0, $user , $pass )

It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for helping me :lmao:

I modified a bit the code like this (in fact there are a lot of users that will be impact by the use of the new application) so I need the script to ask also for the username

but it do not work :-/

#include<process.au3>

$user = InputBox("Username","Please enter your network username")
$pass = InputBox("Passwortd","Please enter your network password")

; DOS-Version: _rundos("net use * \\SRV01\SHARE " & password & " /user:domain" & $bob)

; AutoIt-Version
DriveMapAdd( "*", "\\SRV01\SHARE" ,0, $user , $pass )

I don't understand what is the use of $bob (it should be $user no ?)

Maybe there is a mistake in the modification I did I'm so bad in scripting :-/

I have two question :

- is it possible that when user enter his password *** are displayed whereas the letters ?

- is there a mean to ck eck if the account is locked or the password expired ? (and to tell user to log in with his domain account to set a new valid password) ?

Edited by goonia

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$user = InputBox("Username","Please enter your network username")
$pass = InputBox("Passwortd","Please enter your network password","","*")

; AutoIt-Version
DriveMapAdd( "*", "\\SRV01\SHARE" ,0, "domain\" & $user , $pass )

Edited by ChrisL

Share this post


Link to post
Share on other sites

Not tested, but might help:

#include <Constants.au3>

Global $repeat = 1, $success = 1

While $repeat = 1 
    
    $user = InputBox("Username","Please enter your network username")
    $pass = InputBox("Passwortd","Please enter your network password", "", "*")
    
    SplashTextOn("Please Wait",@LR & "Please Wait...")
        $mapped = DriveMapAdd( "*", "\\SRV01\SHARE" ,0, $user , $pass )
        $err = @error;Let's note if there is any error code
    SplashOff()
    
; Quick-and-dirty way to turn error code into meaningful message
    Dim $errorList = " Undefined / Other error|Access to the remote share was denied|The device is already assigned|Invalid device name|Invalid remote share|Invalid password"
    $errorList = StringSplit($errorList, "|");make an array for error code lookup
    If Not $mapped then
        $success = 0
        If $err = 6 or $err = 2 Then
            $answer = MsgBox(6,"Error", "Username or password is invalid... Please try again.")
            If $answer <> $IDTRYAGAIN Then $repeat = 0
        Else
            $answer = MsgBox(4096,"Error", $errorList[$err])
            If $answer <> $IDTRYAGAIN Then $repeat = 0
        EndIf
    EndIf

WEnd

If $succcess = 0 Then MsgBox(4096,"Warning", "Drive didn't map.  You might need to logon with your domain account and make sure your password has not expired....")

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

Thanks a lot guys !! :lmao:

I not at work anymore (I'm in France) but I will try all that Monday ;)

Share this post


Link to post
Share on other sites

Hey I just made some testing

ChrisL > Thanks your script works fine and displayed * in password box. But if the user has to change his password the drive is not mapped. If so the user do not know what happened

CyberSlug > When I launch the script I get an error message (it sounds like chinese for me)

--

Line 0 (File "D:\test2.exe"):

SplashTextOn("Please Wait",@LR & "Please Wait...")

SplashTextOn("Please Wait",ÊRROR

Error: Unknown macro.

--

Share this post


Link to post
Share on other sites

Change the @LR to @LF


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Change the @LR to @LF

Thanks Smoke_N

I replace @LR to @LF and now I have others error message

In fact when the account is active I get error message :

--

1st a window nammed "Error"

6

a "OK" button

--

Then a new window "AutoIt Error"

Line 0 (file "D:\test2.exe"):

If $success = 0 then msgbox(4096, "warning","drive didn't map. You might need to logon with your domain account and maje sure your password has not expired...")

If ^ERROR

Error: variable used without being decalred

a "OK" button

--

But the drive is mapped

And when the account is to be reactivated I get the same error message and the drive is not mapped.

It seems that there is a syntax error with $success but I'm not sure :lmao:

Share this post


Link to post
Share on other sites

Hmmm, are you evening comparing the errors with what you have? There is one too many 'c'(s) in the last $success there are 3 when there should be 2.

Global $repeat = 1, $success = 1

While $repeat = 1
    
    $user = InputBox("Username","Please enter your network username")
    $pass = InputBox("Passwortd","Please enter your network password", "", "*")
    
    SplashTextOn("Please Wait",@LF & "Please Wait...")
        $mapped = DriveMapAdd( "*", "\\SRV01\SHARE" ,0, $user , $pass )
        $err = @error;Let's note if there is any error code
    SplashOff()
    
; Quick-and-dirty way to turn error code into meaningful message
    Dim $errorList = " Undefined / Other error|Access to the remote share was denied|The device is already assigned|Invalid device name|Invalid remote share|Invalid password"
    $errorList = StringSplit($errorList, "|");make an array for error code lookup
    If Not $mapped then
        $success = 0
        If $err = 6 or $err = 2 Then
            $answer = MsgBox(6,"Error", "Username or password is invalid... Please try again.")
            If $answer <> $IDTRYAGAIN Then $repeat = 0
        Else
            $answer = MsgBox(4096,"Error", $errorList[$err])
            If $answer <> $IDTRYAGAIN Then $repeat = 0
        EndIf
    EndIf

WEnd

If $success = 0 Then MsgBox(4096,"Warning", "Drive didn't map.  You might need to logon with your domain account and make sure your password has not expired....")
I ran this through check, and no errors. (I didn't run it though).


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Hum too many "c".

I made the correction but now I always get the message

"Undefined / Other error"

And then

"Drive didn't map. You might need to logon with your domain account and make sure your password has not expired...."

It happens whenever the drive is mapped or not... any idea ?

(I tried with the account expired/not expired then good password/wrong password ...)

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