iceberg Posted November 10, 2006 Posted November 10, 2006 Hi,Can someone please enlighten me as to why the DriveMapAdd script always gives me error code 2 whereas if I use Net Use, it works fine.Thank you.DriveMapAdd (not working)#NoTrayIcon DriveMapAdd("LPT1:", "\\server\printer", 1, "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.")Net Use (working)RunAsSet("username", "domain", "password") If RunWait("NET USE LPT1: \\server\printer " & "password" & " /USER:" & "domain" & "\" & "username", @TempDir, @SW_HIDE) = 0 Then MsgBox(64, "Printer map", "Successfully mapped drive LPT1:") Else MsgBox(16, "Printer map", "Failed to map drive LPT1:") EndIf RunAsSet() mouse not found....scroll any mouse to continue.
BigDod Posted November 10, 2006 Posted November 10, 2006 Try DriveMapAdd("LPT1:", "\\server\printer", 1, "domain\username", "password") Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother
Danny35d Posted November 10, 2006 Posted November 10, 2006 (edited) DriveMapAdd("LPT1:", "\\server\printer", 1, "domain" & "\" & "username", "password") The syntax look OK to me. It could be a problem with the user credentials, miss typing username or password. For testing only I will change the 1 for a 8 so if the user credentail faild the script will show you an authentication dialog box and try using the same credential or another username and password. Edited November 10, 2006 by Danny35d AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
iceberg Posted November 10, 2006 Author Posted November 10, 2006 BigDOd, thanks for the suggestion. will try it out. Danny35d, no probs with typo. rest assured. ok this is how i tested the scripts. if i log in to the PC using an admin account, the above script works fine where username = domain admin account. but when I log in to the PC using a "limited" account and run the script where username = domain admin account, the script fails. Gives me error code 2. thanks. mouse not found....scroll any mouse to continue.
iceberg Posted November 13, 2006 Author Posted November 13, 2006 BigDod, I used your codes. Still didn't work. Danny35d, I changed "1" to "8" and the dialouge box appears. But even tho i entered the admin user name and password, it keeps popping up. If I click on cancel, it gives me error code 1. mouse not found....scroll any mouse to continue.
Dickb Posted November 13, 2006 Posted November 13, 2006 BigDod, I used your codes. Still didn't work. Danny35d, I changed "1" to "8" and the dialouge box appears. But even tho i entered the admin user name and password, it keeps popping up. If I click on cancel, it gives me error code 1. It might be a user rights problem. Can you try: #NoTrayIcon RunAsSet("username", "domain", "password") DriveMapAdd("LPT1:", "\\server\printer", 1, "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()
iceberg Posted November 13, 2006 Author Posted November 13, 2006 thanks, Dickb. confirm its not user rights problem, cause when I use the same account via NET USE, its working fine. nevertheless, will try your suggestion and see how it goes... mouse not found....scroll any mouse to continue.
iceberg Posted November 14, 2006 Author Posted November 14, 2006 nope...it doesn't work either. gives me error code 2. i am still very puzzled as to why it just doesn't seem to work. Same user name and password used for DriveMapAdd and Net Use. No typo errors! Confirmed. i don't know what else to do....can someone please help? Can you guys test it over at your end to see if u guys face the same problem? Thanks. mouse not found....scroll any mouse to continue.
Danny35d Posted November 16, 2006 Posted November 16, 2006 (edited) DriveMapAdd (not working) #NoTrayIcon DriveMapAdd("LPT1:", "\\server\printer", 1, "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.") Net Use (working) RunAsSet("username", "domain", "password") If RunWait("NET USE LPT1: \\server\printer " & "password" & " /USER:" & "domain" & "\" & "username", @TempDir, @SW_HIDE) = 0 Then MsgBox(64, "Printer map", "Successfully mapped drive LPT1:") Else MsgBox(16, "Printer map", "Failed to map drive LPT1:") EndIf RunAsSet()I forgot that RunAsSet() only work with Run() or Runwait() function. That explain why your net use example work with no problem. The DriveMapAdd script is running as user1 while is trying to map with user2 credentials, the Net Use script is running as user1 then RunAsSet() changed to user2 and map drive with user2 credentials. If you revome both RunAsSet() from the Net Use example, you will have the same problem that you have using DriveMapAdd. To work around you can make the script to run itself with RunAsSet(). #NoTrayIcon If $CmdLine[0] = 0 Then RunAsSet("username", "domain", "password") Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '"') Exit EndIf DriveMapAdd("LPT1:", "\\server\printer", 1, "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() Edited November 16, 2006 by Danny35d AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
iceberg Posted November 17, 2006 Author Posted November 17, 2006 hi Danny35d, i tired the above codes in compiled format. nothing happens....the program just keeps running in task manager. nothing happens.... mouse not found....scroll any mouse to continue.
Danny35d Posted November 17, 2006 Posted November 17, 2006 (edited) hi Danny35d, i tired the above codes in compiled format. nothing happens....the program just keeps running in task manager. nothing happens....Iceberg I'm sorry, but I didn't test the above code. I ran a test on my computer at work and this work. #NoTrayIcon $username = 'username' $password = 'password' $domain = 'domain' $server = '\\server\printer' If $CmdLine[0] = 0 Then RunAsSet($username, $domain, $password) Run('"' & @AutoItExe & '" /runas') Exit EndIf DriveMapAdd("LPT1:", $server, 1, $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.") Edited November 17, 2006 by Danny35d AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
iceberg Posted November 18, 2006 Author Posted November 18, 2006 alright thanks Danny35d. now is Sat morning in my location. will try on Monday morning at work and test it out. thanks. mouse not found....scroll any mouse to continue.
iceberg Posted November 20, 2006 Author Posted November 20, 2006 (edited) hi Danny35d, WORKS LIKE MAGIC! thanks for your patience and assistance. very much appreciated. edit : now the score is 1-1....but whydoesn't it work in the first place? why do we need to do a "RunAs" when DriveMapAdd supposedly should take charge of that? thanks. Edited November 20, 2006 by iceberg mouse not found....scroll any mouse to continue.
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