Jump to content

DriveMapAdd problem


 Share

Recommended Posts

I'm trying to create a function for mapping a network drive using a different user credential (than the person who is currently logged in); however, it doesn't seem to be working. Any thoughts or suggestions on what I'm doing wrong here? I've been wracking my brain over this one!! :)

Func _MapDriveDiffUser($driveletter, $servername, $servershare, $serverusrname, $serverusrpasswd)

If DriveMapGet($driveletter & ":") <> "\\" & $servername & "\" & $servershare Then

DriveMapDel($driveletter & ":")

Sleep(250)

EndIf

DriveMapAdd($driveletter & ":", "\\" & $servername & "\" & $servershare, 0, $serverusrname, $serverusrpasswd)

EndFunc ;==>_MapDriveDiffUser

_MapDriveDiffUser("X","Server1","Public", "domainname\username", "Password123")

Roger O."When people show you who they are, believe them.” --Mark Twain

Link to comment
Share on other sites

Try to extend u'r code like that and inspect the error that is returned.

If DriveMapAdd() function is fail, then Exit code is 1, and a MsgBox with @extended error code will be displayed.

Depending on the number of this @extended error u can make more decisions, like using "net helpmsg <errorcode>"

;
;### map network drives
;

Exit _MapDriveDiffUser("TheLetterYouChoose","YourServerNameHere","YourShareHere", "YourUserNameHere", "YourPasswordHere")


Func _MapDriveDiffUser ($driveletter, $servername, $servershare, $serverusrname, $serverusrpasswd)
    $result = 0
    If DriveMapGet($driveletter & ":") <> "\\" & $servername & "\" & $servershare Then
        DriveMapDel($driveletter & ":")
        Sleep(250)
    EndIf
    If Not DriveMapAdd($driveletter & ":", "\\" & $servername & "\" & $servershare, 0, $serverusrname, $serverusrpasswd) Then
        $result = @error
        MsgBox (0, "Extended error", "Error " & $result & " with extended code " & @extended)
    EndIf
    Return $result
EndFunc;==>_MapDriveDiffUser

p.s. Your code looks fine, think the problem not in it is.

upd. forgot to delete passwords etc. :)

Edited by Arnautov
Link to comment
Share on other sites

Thanks for your help. I figured out the problem -- I was trying to map a share on a server where I already had drives mapped using a different user credential. The fully functional script is attached, in case someone wants to us it.

Try to extend u'r code like that and inspect the error that is returned.

If DriveMapAdd() function is fail, then Exit code is 1, and a MsgBox with @extended error code will be displayed.

Depending on the number of this @extended error u can make more decisions, like using "net helpmsg <errorcode>"

MapDriveDiffUser.au3

Roger O."When people show you who they are, believe them.” --Mark Twain

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