Sign in to follow this  
Followers 0
Wolfteeth

Very bad on DriveMapAdd

8 posts in this topic

#1 ·  Posted (edited)

Dear All,

I'm getting crazy due to the very bad interactive with DriveMapAdd, How can I always get the error: "undefined/error" when using such command parameter?

could anyone who can help to check the how the DriveMapadd is working?

usually, I used to use batch file for that coding, it works greatly, but when I want to transfer to AutoIt3, I encountered unacceptable problem, why it doesn't work??? my understanding problem on DriveMapAdd? Could someone help me to transfer the Batch code to Autoit3? In fact, the batch file can enum the remote computer's local password and get the network driver session.

CODE

@echo off

if {%1}=={} goto noparms

net use x: /del

net use x: \\%1\c$ /user:%1\localadmin Local2008

if %errorlevel% equ 2 goto zero

Echo Succeed: localadmin Local2008 for %1

goto succeed

:noparms

echo Usage: Map PCname [Administrator] [Password]

echo Usage: Default Password is Password

net use x: /del

goto succeed

:zero

net use x: \\%1\c$ /user:%1\Ladmin Ladmin2008

Echo Succeed: Ladmin Ladmin2008 for %1

goto succeed

:succeed

CODE

$username = "localadmin"

$password = "Local2008"

$domain = "Gx001" ; please note Gx001 is just a remote computer name not a domain server name

$server = "\\Gx001\c$"

; it seems I want to use: net use X: \\gx001\c$ /user:gx001\localadmin Local2008 to get the network driver session

If $CmdLine[0] = 0 Then

RunAsSet("username", "domain", "password")

DriveMapDel("x:")

Exit

Else

$PCname=$CmdLine[1]

RunAsSet($username, $domain, $password)

DriveMapAdd("x:", $server, 0, $domain & "\" & $username, $password)

If @error = 0 Then MsgBox(64, "LPT1: is mapped to", DriveMapGet("LPT1:"))

If @error = 1 Then MsgBox(16, "ERROR", "Undefined/Other error.")

If @error = 2 Then MsgBox(16, "ERROR", "Access to the remote share was denied.")

If @error = 3 Then MsgBox(64, "WARNING", "The device is already assigned.")

If @error = 4 Then MsgBox(16, "ERROR", "Invalid device name.")

If @error = 5 Then MsgBox(16, "ERROR", "Invalid remote share.")

If @error = 6 Then MsgBox(16, "ERROR", "Invalid password.")

RunAsSet()

EndIf

Edited by Wolfteeth

Share this post


Link to post
Share on other sites



1) RunAsSet() only work with Run() and RunWait() function, so in your script it not doing anything.

2) I don't know if you did this for testing. DriveMapAdd("x:", $server, 0, $domain & "\" & $username, $password) but it should be DriveMapAdd("x:", "\\" & $PCname & "\C$", 0, $PCname & "\" & $username, $password)

3) In the batch script if it fail mapping with localadmin Local2008 account then try to map using Ladmin Ladmin2008 account. May be this is the main reason why your script is not working.

$username = "localadmin"
$password = "Local2008"

; it seems I want to use: net use X: \\gx001\c$ /user:gx001\localadmin Local2008 to get the network driver session

If $CmdLine[0] = 0 Then
    MsgBox(16,"Map Drive","Usage: Map PCname [Administrator] [Password]" & @CRLF & "Usage: Default Password is Password")
    DriveMapDel("x:")
    Exit
Else
    $PCname = $CmdLine[1]
    $SuccesMapping = DriveMapAdd("x:", "\\" & $PCname & "\C$", 0, $PCname & "\" & $username, $password)
    _CheckError(@error, @extended)
    If Not $SuccesMapping Then
        $username = "Ladmin"
        $password = "Ladmin2008"
        $SuccesMapping = DriveMapAdd("x:", "\\" & $PCname & "\C$", 0, $PCname & "\" & $username, $password)
        _CheeckError(@error, @extended)
    EndIf
    
    If $SuccesMapping Then MsgBox(64,"Succeed Mapping","Succeed: " & $username & ' ' & $password & ' for ' & $PCname)
EndIf

Func _CheckError($iError, $iExtended = '')
    Switch $iError
        ;Case 0
        ;   MsgBox(64, "LPT1: is mapped to", DriveMapGet("LPT1:"))
        Case 1
            MsgBox(16, "ERROR", "Undefined/Other error." & @CRLF & "Extended error: " & $iExtended)
        Case 2
            MsgBox(16, "ERROR", "Access to the remote share was denied.")
        Case 3
            MsgBox(64, "WARNING", "The device is already assigned.")
        Case 4
            MsgBox(16, "ERROR", "Invalid device name.")
        Case 5
            MsgBox(16, "ERROR", "Invalid remote share.")
        Case 6
            MsgBox(16, "ERROR", "Invalid password.")
    EndFunc
EndFunc
I commented out @error = 0, I didn't see it on the help file. The help file only mention from @error 1 to @error 6.

Note: If this doesn't work change DriveMapAdd flag from 0 to 8 it will show you authentication dialog if it needed.


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi, Danny35D,

Oops...crazy again...I abhor the drivemapadd and no good debug console step by step..... don't know how it doesn't work....can you please help to check it again?

indeed, your code is working...that's sucks. no any coding changed, why not me??? $username and $password can get the correct string but faild still to map driver... wanna catch hold of neck of the author of Autoit3 and shake away, because of he makes me loving in the hell...I beg him to improve the drivemapadd source coding and import the Kix32's "netuse" function...

CODE

; Created by Wolfteeth

; Modified on 9:52 AM

Local $AArray[8]

$AArray[0]="localadmin,local2008"

$AArray[1]="administrator,local2000"

$AArray[2]="ladmin,Lamdin2008"

$AArray[3]="Local,local2000"

$AArray[4]="gusadmin,gus55555"

$AArray[5]="guslocal,guslocal"

$AArray[6]="xxxx,xxxxxx"

$AArray[7]="yyyy,yyyyyy"

; it seems I want to use: net use X: \\gx001\c$ /user:gx001\localadmin Local2008 to get the network driver session

If $CmdLine[0] = 0 Then

MsgBox(16,"Map Drive","Usage: Map PCname [Administrator] [Password]" & @CRLF & "Usage: Default Password is Password")

DriveMapDel("x:")

Exit

Else

$PCname = $CmdLine[1]

$i = 0

$flag = 0

Do

$BArray = StringSplit($AArray[$i],',',1)

$username=$BArray[1]

$password=$BArray[2]

$SuccesMapping = DriveMapAdd("x:", "\\" & $PCname & "\C$", 0, $PCname & "\" & $username, $password)

_CheckError(@error, @extended)

If $SuccesMapping Then

ConsoleWrite("Succeed: " & $username & ' ' & $password & ' for ' & $PCname)

$flag = 1

Else

$flag = 0

MsgBox(64,"","unsuccess")

EndIf

$i = $i + 1

Until ($flag = 1) or $i>=UBound($AArray)

If Not $SuccesMapping Then

ConsoleWrite("UnSucceed!, no valid password match for " & $PCname )

; MsgBox(64,"Unsucceed Mapping","UnSucceed!, no valid password match for " & $PCname)

EndIf

EndIf

Func _CheckError($iError, $iExtended = '')

Switch $iError

;Case 0

; MsgBox(64, "LPT1: is mapped to", DriveMapGet("LPT1:"))

Case 1

MsgBox(16, "ERROR", "Undefined/Other error." & @CRLF & "Extended error: " & $iExtended)

Case 2

MsgBox(16, "ERROR", "Access to the remote share was denied.")

Case 3

MsgBox(64, "WARNING", "The device is already assigned.")

Case 4

MsgBox(16, "ERROR", "Invalid device name.")

Case 5

MsgBox(16, "ERROR", "Invalid remote share.")

Case 6

MsgBox(16, "ERROR", "Invalid password.")

EndSwitch

EndFunc

Edited by Wolfteeth

Share this post


Link to post
Share on other sites

I don't see anything wrong with the code, also I don't anything about your network. At work after trying account three times with the wrong password will lock the computer, don't know if this is the case at your network. The only thing I changed on your script instead of using Do Until function I'm using For Next.

; Created by Wolfteeth
; Modified on 9:52 AM

Local $AArray[8]
$AArray[0] = "localadmin,local2008"
$AArray[1] = "administrator,local2000"
$AArray[2] = "ladmin,Lamdin2008"
$AArray[3] = "Local,local2000"
$AArray[4] = "gusadmin,gus55555"
$AArray[5] = "guslocal,guslocal"
$AArray[6] = "xxxx,xxxxxx"
$AArray[7] = "yyyy,yyyyyy"

; it seems I want to use: net use X: \\gx001\c$ /user:gx001\localadmin Local2008 to get the network driver session

If $CmdLine[0] = 0 Then
    MsgBox(16, "Map Drive", "Usage: Map PCname [Administrator] [Password]" & @CRLF & "Usage: Default Password is Password")
    DriveMapDel("x:")
    Exit
Else
    $PCname = $CmdLine[1]
    For $i = 0 To UBound($AArray) - 1
        $BArray = StringSplit($AArray[$i], ',', 1)
        $username = $BArray[1]
        $password = $BArray[2]
    
        $SuccesMapping = DriveMapAdd("x:", "\\" & $PCname & "\C$", 0, $PCname & "\" & $username, $password)
        _CheckError(@error, @extended)
        If $SuccesMapping Then
            ConsoleWrite("Succeed: " & $username & ' ' & $password & ' for ' & $PCname)
            ExitLoop
        Else
            MsgBox(64, "", "unsuccess")
        EndIf
    Next
    If Not $SuccesMapping Then
        ConsoleWrite("UnSucceed!, no valid password match for " & $PCname)
        ; MsgBox(64,"Unsucceed Mapping","UnSucceed!, no valid password match for " & $PCname)
    EndIf
EndIf

Func _CheckError($iError, $iExtended = '')
    Switch $iError
        ;Case 0
        ; MsgBox(64, "LPT1: is mapped to", DriveMapGet("LPT1:"))
        Case 1
            MsgBox(16, "ERROR", "Undefined/Other error." & @CRLF & "Extended error: " & $iExtended)
        Case 2
            MsgBox(16, "ERROR", "Access to the remote share was denied.")
        Case 3
            MsgBox(64, "WARNING", "The device is already assigned.")
        Case 4
            MsgBox(16, "ERROR", "Invalid device name.")
        Case 5
            MsgBox(16, "ERROR", "Invalid remote share.")
        Case 6
            MsgBox(16, "ERROR", "Invalid password.")
    EndSwitch
EndFunc   ;==>_CheckError

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

O yeah... For Next has the Exitlop function... of course, we could use it to enhance the readability...

anyway, the account would'nt be locked as I could use net use to map the driver in the batch script.

Yes, coding is correct, but couldn't do what we expected that is what I said:"DriveMapAdd function is very very very bad!!!"

it's just a very small and slim function but can't get to work due to unknown reason, so can't be accepted for that great script!!!

nevertheless, I will try your coding again. thanks.

Share this post


Link to post
Share on other sites

...Danny35D, Sorry, your code is said failure again with Undefined/Other error. :)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Maybe x: is already mapped. Try this...

DriveMapDel("x:")
DriveMapDel("\\" & $PCname & "\C$")
$SuccesMapping = DriveMapAdd("x:", "\\" & $PCname & "\C$", 0, $PCname & "\" & $username, $password)
Edited by Joon

Share this post


Link to post
Share on other sites

X is freedom..

Maybe x: is already mapped. Try this...

DriveMapDel("x:")
DriveMapDel("\\" & $PCname & "\C$")
$SuccesMapping = DriveMapAdd("x:", "\\" & $PCname & "\C$", 0, $PCname & "\" & $username, $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