ShminkyBoy Posted October 1, 2008 Posted October 1, 2008 (edited) Ok, new thread, same topic; hopefully someone can help me solve this =) I need to retreive the user's name *and* password to silently set up network shares. the working .bat file commands are as follows: REM V: Drive Net Use V: /Delete IF ERRORLEVEL 1 @ECHO No V: Drive to reset, continuing... Net Use V: \\10.1.0.45\Home %PASSWORD% /user:%USERNAME% IF ERRORLEVEL 1 pause Here's what I have so far in AutoIT, which fails: expandcollapse popup#NoTrayIcon #include "Misc.au3" ;` Run only one instance if _Singleton("Remap",1) = 0 Then Exit EndIf ;~ Update environment variables EnvUpdate() $Status = RemapShare("V:","\\10.1.0.45\Home",EnvGet("USERNAME"),EnvGet("PASSWORD")) If @error then MsgBox(0x41010,"COMPANY network share - Error!","Drive V: " & $Status & " - Error code " & @error & ". ",5) ;~ End exit ;~ Remap persistent net shares Func RemapShare($sDriveLetter, $sNetPath, $sUsername = "username", $sPassword = "password") $RetVal = DriveMapGet($sDriveLetter) If @error > 0 Then $RetVal = DriveMapAdd($sDriveLetter, $sNetPath, 0, $sUsername, $sPassword) If @error > 0 Then Seterror(1) return "FAILED" EndIf seterror(0) Return "MAPPED" Else If $RetVal <> $sNetPath Then SetError(2) Return "CONFLICT" EndIf $RetVal = DriveMapDel ($sDriveLetter) If @error > 0 Then Seterror(3) return "FAILED" EndIf $RetVal = DriveMapAdd($sDriveLetter, $sNetPath, 0, $sUsername, $sPassword) If @error > 0 Then Seterror(4) return "FAILED" EndIf seterror(0) Return "REMAPPED" Endif Endfunc Basically, I want the script to silently remap the drive share using the logged on user's credentials with no user intervention. I figured I could use EnvGet() to get the user password from the environment variable, but it fails at the drivemapadd() line Is this incorrect? Is there another way to do what I want? Edited October 1, 2008 by ShminkyBoy Urban Terror - ioUrban Terror website Like-yea
archgriffin Posted October 1, 2008 Posted October 1, 2008 If the script is running as the user, and it attempts to map a drive it should use their network creds automatically. So you should be able to omit those options on the DriveMapAdd function. At least that is how it works for me in my environment, with is a domain setup. I did not see the other thread, so I am not sure what others have already told you, sorry if it is repetitive. "Human kind cannot gain anything without first giving something in return, to obtain; something of equal value must be lost."The Help File is truly your friend.
ShminkyBoy Posted October 1, 2008 Author Posted October 1, 2008 If the script is running as the user, and it attempts to map a drive it should use their network creds automatically. So you should be able to omit those options on the DriveMapAdd function.At least that is how it works for me in my environment, with is a domain setup.I did not see the other thread, so I am not sure what others have already told you, sorry if it is repetitive.Thank you, this worked! Urban Terror - ioUrban Terror website Like-yea
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now