Jump to content

Need help to map drive


goonia
 Share

Recommended Posts

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

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

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
Share on other sites

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

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

--

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

Link to comment
Share on other sites

  • Moderators

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

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.

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

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